#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?

Recommended Answers

All 6 Replies

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
Member Avatar for masterofpuppets

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

Member Avatar for masterofpuppets

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 ] )

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])

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

Member Avatar for masterofpuppets

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.