I have a code:
import random
vowels, consonants='aeiou','bcdfghjklmnpqrstvwxyz'
terms = int(input("How many letters you want for your baby's name? "))
def babyname():
for i in range(0, terms):
j=['','','','','']
k = input("What letter do you want? Enter 'v' for vowels, 'c' for consonants: ")
if k == 'v':
j[i] = random.choice(vowels)
elif k == 'c':
j[i] =random.choice(consonants)
else:
k = input("What letter do you want? Enter 'v' for vowels, 'c' for consonants: ")
print(j)
babyname()
Input: i) It will ask for the number of letters for the word to be generated. ii)It will ask whether the letter should be consonant or vowel for each letter.
Expected output: i) Print the generated word with the inputted number of letters
But output yielded: i) Only the letter generated before the limit. If 5 is entered. It generates the 5th letter only.
What I did: I thought of making the variable j a list with index i so that I can add all the strings later to generate the word. But it is not happening.
What to do?
alist? it seems like all you need to do is comparek == 'v'ork == 'c'.j = a[i]?