I'm making a pseudo-word (fake, real-sounding word) generator, it was working as expected, but then I decided to make it so it can generate more than one word at a time, (you give it "n" and it gives you "n" number of words). So I put it all in a for loop... and it works... but say for example you ask for 6 words, it gives you the same word 6 times instead of generating a new word each time.
import random
wordend = "false"
word = ""
sniptypes = ["v","c"]
vowels = ["a","e","i","o","u"]
vends = ["a","e","y","o","u"]
#vends is short for vowel ends (for when a word ends with a vowel)
cends = ["b","c","d","f","k","l","m","h","n","p","g","q","s","r","t","v","w","x","y","z"]
#cends is short for consonant ends (these are the consonants the words are allowed to end with)
dends = ["kt","rt","ld","rc","rk","fk","lm","by","ch","ck","cy","dy","fy","gh","gy","ky","ly","quy","my","ny","nd","pt","ph","py","ry","rg","rf","rd","xy","sb","sh","sk","sp","st","sy","th","ty","wy","ss","tt","ll","nm","mn"]
#dends is short for double ends (pair of consonants that sound well at the end of a word: chalCK)
consonants = ["b","c","d","f","g","h","j","k","l","m","n","p","qu","r","s","t","v","w","x","y","z"]
doubles = ["bl","br","ch","ck","cl","cr","dl","dr","fl","fn","fr","fy","gh","gl","gr","gn","vy","kl","kn","kr","xy","zy","ly","pn","pt","ph","pl","pr","py","sb","sc","sh","sk","sl","sn","sm","sp","squ","st","sv","sy","th","tl","tr","ty","ts","vl","wh","wr","ll","tt","ss"]
#doubles are a pair of consonants that sound well at the beggining of a word: CHalk.
lengths = [2,3,3,4,4,4,4,5,5,6]
for i in range(int(input("how many words? "))):
lenght = random.choice(lengths)
sniptype = random.choice(sniptypes)
snipnumb = lenght
while wordend == "false":
snipnumb -= 1
if sniptype == "v":
r1 = random.random()
if r1 < (5/21):
r2 = random.random()
if r2 < (1/5):
word += random.choice(vowels)
word += random.choice(vowels)
if snipnumb == 0:
word += random.choice(vends)
elif snipnumb > 0:
word += random.choice(vowels)
else:
print("error")
elif r2 >= (1/5):
word += random.choice(vowels)
if snipnumb == 0:
word += random.choice(vends)
elif snipnumb > 0:
word += random.choice(vowels)
else:
print("error")
else:
print("error")
elif r1 >= (5/21):
if snipnumb == 0:
word += random.choice(vends)
elif snipnumb > 0:
word += random.choice(vowels)
else:
print("error")
else:
print("error")
sniptype = "c"
elif sniptype == "c":
r1 = random.random()
if r1 < (6/21):
r2 = random.random()
if r2 < (1/6):
if snipnumb == 0:
word += random.choice(dends)
elif snipnumb > 0:
word += random.choice(consonants)
word += random.choice(doubles)
else:
print("error")
elif r2 >= (1/6):
if snipnumb == 0:
word += random.choice(dends)
elif snipnumb == (lenght-1):
word += random.choice(doubles)
elif snipnumb > 0:
word += random.choice(consonants)
word += random.choice(consonants)
else:
print("error")
else:
print("error")
elif r1 >= (6/21):
if snipnumb == 0:
word += random.choice(cends)
elif snipnumb > 0:
word += random.choice(consonants)
else:
print("error")
else:
print("error")
sniptype = "v"
else:
print("error")
if snipnumb == 0:
wordend = "true"
print(word)
I expect it to make n different words, instead, it makes one word and prints it n times.
Aucun commentaire:
Enregistrer un commentaire