I want to create a generator for me and my cousin to play a game with random equipment in the game. However when i would use the while loop and the if's and elif's and the random.choice it would give me random things all the time. I would get guns when i ask for armor instead.
For example if i had:
names_invited = ["Kreg, George"]
names_at_party = ["Blue", "Connor"]
names_not_at_party = ["Dixon","Donnor"]
names_not_invited = ["Sindy, Grinch"]
name__from_bothlists = [names_invited, names_not_invited]
print(random.choice(names_invited))
x = 1
while x == 1:
ask = input("What name?: ")
if ask == "notinvited":
**name_selector = random.selector(name_bothlists)**
print(random.choice(names_from_bothlists))
elif ask == "atparty":
print(random.choice(names_at_party))
Then I would get:
What name?: "atparty"
It gives me:
Grinch (which is from the not_invited list)
My problem is i have different lists and its getting a random one from the wrong list. Ive figured out where the problem is.... its the name_selector == random.choice. if i removed that it was fine because i had other elifs and if statements however, when i do remove that i still would get the list and not the specific random item. in this case.
['Sindy', 'Grinch']
Though it all works. i just want to be able to select that specific one... without the issue of trying to use another list and getting one from the both list group.
Simple breakdown: Im trying to have a list of lists that select a random item. However when i have the "selector = random.choice()" it uses only that list of lists. So when i have my armor list in my project, i ask for a random choice from there and get an item from my guns list.
Aucun commentaire:
Enregistrer un commentaire