On 08/22/2010 09:35 PM, Roelof Wobben wrote:
Hello,
I made this programm :
def count_letters(n,a):
count = 0
for char in n:
if char == a:
count += 1
return count
fruit=""
letter=""
fruit= input("Enter a sort of fruit: ")
teller = input("Enter the character which must be counted: ")
x=count_letters (fruit,letter)
print "De letter", letter , "komt", x , "maal voor in het woord", fruit
The problem is that I can't have the opportuntity for input anything.
I use python 2.7 on a Win7 machine with as editor SPE.
Roelof
Also, you have a typo in your code (teller instead of letter) so fix
that too :)
A couple more comments:
- You don't have to initialize fruit and letter. Doesn't make sense in
this context.
- Although I can see you made the count_letters() function as an
exercise, there is a build in method of string that accomplishes the
same effect.
Try x=fruit.count(letter)
- Give a bit of thought about what would happen if someone enters a
whole string instead of a character for letter. How should your program
accommodate that?
Nick
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor