GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Feb-2008, 15:54
madpotential madpotential is offline
New Member
 
Join Date: Feb 2008
Posts: 2
madpotential is on a distinguished road

Determine the number of words and characters


I need help with a program that determines the number of words and characters, so far all I have is

input string

def wcount(f):
"""Print three numbers showing the count of lines, words and
characters in the file f .
input = words
input = characters



def findInstances(t, s):
"""Print the list of all indices with string s where an instance of the
substring t is found.

raw input = words
raw input = characters

output = words & characters
  #2  
Old 24-Feb-2008, 20:40
fonz87 fonz87 is offline
New Member
 
Join Date: Jan 2008
Posts: 12
fonz87 has a little shameless behaviour in the past

Re: Need help with a program..


hey, r u trying to write a program that counts characters and words and lines from the file ??
if so, let me know. i can help you with that.
  #3  
Old 26-Feb-2008, 08:23
madpotential madpotential is offline
New Member
 
Join Date: Feb 2008
Posts: 2
madpotential is on a distinguished road

Re: Determine the number of words and characters


yes that is what i am trying to do
  #4  
Old 26-Feb-2008, 21:12
fonz87 fonz87 is offline
New Member
 
Join Date: Jan 2008
Posts: 12
fonz87 has a little shameless behaviour in the past

Re: Determine the number of words and characters


Here is program that I did while back couple of weeks ago.

It's written all in one window instead of throughout different windows. I am not sure how you guys are programming but our teacher is teaching us different ways to do it.

The file name has to be different since I had it named different

Python Code:
import string

def main():
    myfile=open("textfile.txt",'r')
    sum=0
    words=0
    characters=0
    for line in myfile:
        sum=sum+1 
        for word in string.split(line):
            words=words+1
            for ch in word:
                characters=characters+1
           
    print sum
    print words
    print characters
main()
Last edited by admin : 27-Feb-2008 at 05:49. Reason: Please insert your example Python codes between [PY] and [/PY] tags
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
Text-Based Roulette Game mfm1983 C++ Forum 5 29-Nov-2006 13:20
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 04:48
Pipeline freeze simulation darklightred C++ Forum 6 27-Jul-2006 20:37
How to read particular memory location ? realnapster C Programming Language 10 10-May-2006 10:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:05.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.