samedi 4 février 2023

Print 5 Chinese Fortunes 1 at a time randomly from a list, input yes, print another fortune from the list without repetition

I am trying to make a python program that prints 5 different chinese fortune cookie fortunes from a list. It will print one the ask "Would you like another fortune?" User replies yes, then it prints another fortune randomly selected from the list, until all five have been printed.

My issue is I do not know how to write the code so that there are no repetitions from the list.

I am very new to python, like 60 pages into the book I'm reading new.

import random 

fortunes_list = ['Good fortunes to you', 'chinese stuff', 'the sauce is the sauce', 'too much sauce can be a bad thing',
'if its some gang, its some gang']


sampled_fortunes = random.sample(fortunes_list, 1)

print(sampled_fortunes) 

input("do you want another fortune?")

answer = ""

while answer != "no":
    print(sampled_fortunes)
    input("do you want another fortune?")
import random 

fortunes_list = ['Good fortunes to you', 'chinese stuff', 'the sauce is the sauce', 'too much sauce can be a bad thing',
'if its some gang, its some gang']

print(random.choice(fortunes_list)) 

input("do you want another fortune?")

answer = ""

while answer != "no":
    print(random.choice(fortunes_list))
    input("do you want another fortune?")





Aucun commentaire:

Enregistrer un commentaire