15,742,263 members
1.00/5 (1 vote)
See more:
"""a program that asks the user
for the number of lines for the entered poem.
It then allows the user to enter the desired number of lines.
Then output the number of lines,
vowels and consonants in the poem and in each line."""

I tried this for a string.
But I am not able to think of vowels and consonants in each line.

What I have tried:

Python
```strg = input("Please Enter Your Own String : ")
vowels = 0
consonants = 0

for i in strg:
if (i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'
or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
vowels = vowels + 1
else:
consonants = consonants + 1

print("Number of Vowels: ", vowels)
print("Number of Consonants: ", consonants)```
Posted
Updated 23-Sep-22 17:18pm
v3
Richard MacCutchan 25-May-21 3:32am
Your if statement could be simplified to:
```if i in 'aeiouAEIOU':
vowels = vowels + 1
```

## Solution 1

Put that code in a function.
Call it for each line.

You'll have to make a few changes but anyone who can write that code shouldn't have any problem doing that as it's pretty easy stuff.

## Solution 3

Quote:
a program that asks the user
for the number of lines for the entered poem.

This means that user input is sentences,which imply that input contains non letters like spaces, commas or points.
Python
```if (i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'
or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
vowels = vowels + 1
else:
consonants = consonants + 1
```

So, what is not a vowel is not necessary a consonant, you need to check if a char is a consonant, or not.

## Solution 4

vowels = 0
consonants = 0

for i in strg:
if i in 'aiueoAIUEO':
vowels = vowels + 1
consonants = consonants + 1

print("Number of Vowels: ", vowels)
print("Number of Consonants: ", consonants)