0

So I'm writing a basic program that counts the number of characters in a user's name and the number of times each vowel occurs. However, it only counts if the user inputs upper-case letters, but I have set it to convert the string to lower-case.

n = input("Please enter your name: ")
n.lower()
x = (len(n))
a = n.count('a')
e = n.count('e')
i = n.count('i')
o = n.count('o')
u = n.count('u')

print("Your name has {0} a, {1} e, {2} i, {3} o, {4} u and is {5} characters long.".format(a,e,i,o,u,x))

What's wrong with this?

discord1
  • 31
  • 1
  • 3
  • 8
  • `n = n.lower()`, not `n.lower()`. Strings are immutable and do not change when you call their methods. – zondo Apr 10 '16 at 12:51

1 Answers1

3

you must assign to n; n.lower() does not change n, but returns a new string in lower case.

replace:

n.lower()

with:

n = n.lower()
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80