This is a random username generator. The problem is with the themes list. themes is clearly defined themes = ["Possum", "Pirate", "Plant"]
if request.lower() not in themes: If this line of code and its subsequent nested lines are above this line:
if request.lower() == ("possum"):
The terminal reads:
name's name generator v1
Enter a theme: **pirate**
**That is not a supported theme in this version**
Would you like a list of currently supported themes? yes
['Possum', 'Pirate', 'Plant']
Enter a theme: **plant**
**That is not a supported theme in this version**
Would you like a list of currently supported themes?
It's looping, but this doesn't really make sense to me because if I place:
if request.lower() not in ["possum", "pirate", "plant"]: instead of if request.lower() not in themes:
Writing the list out. It works perfectly when sequenced :
request = input("Enter a theme: ")
if request == "q":
quit()
if request.lower() not in ["possum", "pirate", "plant"]:
blah blah blah
if request.lower() == ("possum"):
blah blah blah
Here is the completed working code. I changed it to an elif and moved it to the bottom of my script.
import random
usernameposs = ["possum", "poss","oposs", "opossum"]
usernamepirate = ["pirate", "cap'n", "deckhand", "floor-swabber"]
usernameplant = ["plant", "shroom", "succulent", "garden"]
surname = ["man", "guy", "lord", "vanheel", "fungicide", "beard", ]
themes = ["Possum", "Pirate", "Plant"]
print("name's name generator v1")
while True:
random_number = random.randint(0, 3) #number of firstnames
random_number2 = random.randint(0,5) #number of surnames
request = input("Enter a theme: ")
if request == "q":
quit()
if request.lower() == ("possum"):
print(usernameposs[random_number], surname[random_number2])
request = input("Would you like to generate another username? ")
if request.lower() == "yes":
continue
else:
quit()
elif request.lower() == ("pirate"):
print(usernamepirate[random_number], surname[random_number2])
request = input("Would you like to generate another username? ")
if request.lower() == "yes":
continue
else:
quit()
elif request.lower() == ("plant"):
print(usernameplant[random_number], surname[random_number2])
request = input("Would you like to generate another username? ")
if request.lower() == "yes":
continue
elif request.lower() not in themes:
print("That is not a supported theme in this version" )
supp_theme = input("Would you like a list of currently supported themes? ")
if supp_theme.lower() == "yes":
print(themes)
continue
elif supp_theme.lower() == "no":
print("Okay, you can enter q to quit")
continue
elif supp_theme.lower() == "q":
quit()
else:
print("stop trying to break it!:)")
else:
quit()
Why does it work with when I type the list out, but not when I call the defined above themes? And why does calling themes work when I place the whole if statement as an elif at the bottom of the script?
source https://stackoverflow.com/questions/70687849/why-wont-my-project-work-when-oriented-a-specific-way
Comments
Post a Comment