Jul-01-2020, 05:20 PM
Hi, so I made this programme which shows a different number when it runs(dice). The problem is when I type yes to : Do you want to roll again, it gives me the same random integer back even though the method is supposed to give me a different one. This is fixed however by manually rerunning the code. Is there a way that I could do this in the code?
import random # a function where when it runs it prints a # random number between 1 and 6 # then it should ask you if you want to roll again dice = random.randint(1, 6) # create a function that runs and prints ask_again = True def roll_dice(): global ask_again print(dice) answer = input("Do you want to roll again?: \n") if answer == "no" or answer == "No": ask_again = False elif answer == "Yes" or answer == "yes": ask_again = True while ask_again: roll_dice()