0
How can I make my code more compact?
9 Answers
+ 10
#This does the same thing with less code:
a = input()
for x in "aeiou":
print(f"{x.upper()} letters:\n{a.count(x)}")
+ 5
https://code.sololearn.com/cvt7D5enFIDc/?ref=app
Aege See this....
+ 5
I used a technique known as string interpolation. The string is prefixed with the letter f"...". Inside the string there are braces. Whatever is found between the braces gets evaluated as a program expression. The result gets converted to a string and inserted in place.
Both, upper (convert to uppercase) and count, are methods supplied by the string class.
+ 4
Brian nice explanation š
+ 4
Hi, just noticed that the code of Aege and Brian won't result in any vowel count if the input is in all capital letters. Thanks.
+ 3
Cris Tradio good observation. I noticed it also, but decided to keep my code true to the original. An easy adjustment would be to convert the input string to all uppercase. Now this counts all vowel letters:
a = input().upper()
for x in "AEIOU":
print(f"{x} letters:\n{a.count(x)}")
+ 2
Thanks Brian!
+ 1
Yeah, the only problem is that it doesn't recognize which vowel is, thx by the way
0
Wow, which function are you using? How is it called?