+ 1
problems getting new random choices
while I was trying to make a fun magic 8 ball program this evening everything was working out fine, however, I want the program to make a different random choice every time there is a new user input how can I do that without having to restart it every time I want to ask it a new question I tried both random,choice and random.sample and I tried containing it within a while loop (although I'm not sure if I did that right), any suggestion would be great. https://code.sololearn.com/cIM1z31exL85
4 ответов
+ 3
import random
def magic_eight():
my_list = ["It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "You may rely on it", "As I see it...yes",
"Most likely", "Outlook good", "Yes", "Signs point to yes", "Reply hazy try again", "Ask again later", "Better not tell you now",
"Cannot predict now", "Concentrate and ask again", "Dont count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"]
while True:
print ("""
Magic 8 Ball!
Ask any question you desire!
(yes or no only)
""")
user_input = input(": ")
if user_input == "q":
break
else:
value = random.choice(my_list)
print(value)
magic_eight()
+ 2
shuffle the list at the beginning once
then output first, second, third... element
when you output last element, shuffle the list again (then the answers must repeat, because there is only a finite number of them)
+ 2
thanks that makes a ton of sense, I'm new to all this so that helps a lot!
0
yeah, put value inside the whole loop