0
#Program to count number of specific vowels

msg = input("Enter a message:")
msg_lower = msg.lower()
VOWELS = list(aeiou)
msg_list = list(msg_lower)
x = ()
for letter in VOWELS:
    x[letter] = msg_list.count(letter)
for letter in x:
    print(a, x(letter))
    print(e, x(letter))
    print(i, x(letter))
    print(o, x(letter))
    print(u, x(letter))

I get an error after I try to input any thing. I get a Name Error?

5
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by masterofpuppets
0

Your program should be

#Program to count number of specific vowels

msg = input("Enter a message:")
msg_lower = msg.lower()
VOWELS = list("aeiou")
msg_list = list(msg_lower)
x = dict()
for letter in VOWELS:
    x[letter] = msg_list.count(letter)
for letter in x:
    print(letter, x[letter])

When there is an error, please put the traceback in your posts. The traceback was

Traceback (most recent call last):
  File "vow.py", line 5, in <module>
    VOWELS = list(aeiou)
NameError: name 'aeiou' is not defined
0

Probably you get the error because you are using the input() function when for textual input you should use raw_input()

By the way you could use input() but you need to put whatever you type in quotes "" otherwise they can be omitted :)

hope that helps

0

Is this what you are trying to do?

msg = input("Enter a message: ")
msg_lower = msg.lower()
VOWELS = [ "a", "e", "o", "u", "i" ]
msg_list = list( msg_lower )
x = {} # x is a dictionary
for letter in VOWELS:
    x[ letter ] = msg_list.count( letter ) # access values in dictionary using x[...]

for letter in x:
    print( letter, x[ letter ] )

Edited by masterofpuppets: n/a

0

Probably you get the error because you are using the input() function when for textual input you should use raw_input()

By the way you could use input() but you need to put whatever you type in quotes "" otherwise they can be omitted :)

hope that helps

Looks like the OP is using Python3 where raw_input() has been replaced with input().

Note that strings and lists are iterable sequences and both have the count() function, so your code could be simplified to ...

# Program to count number of specific vowels
# using python3

msg_lower = input("Enter a message:").lower()
VOWELS = "aeiou"

x = dict()
for letter in VOWELS:
    x[letter] = msg_lower.count(letter)

for letter in x:
    print(letter, x[letter])

Edited by vegaseat: code

0

At least for some time, it would be very nice if people indicated which version of Python they are using.

0

At least for some time, it would be very nice if people indicated which version of Python they are using.

I'm using Python 2.5.2 :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.