Jan-18-2017, 11:33 AM
Hey there. I started learning code yesterday and my second program is a dice rolling game. The object is to roll a higher number than the computer. The game is of course completely random.
I would like to have an option at the end of the game which says: "do you want to restart? Yes or No". If the user types yes, the game restarts (and this an infinite number of times, until the user has had enough of the game and ragequits xD) . I know you can do this with a loop, but how?
Excuse my lack of experience,
thanks in advance,
me.
I would like to have an option at the end of the game which says: "do you want to restart? Yes or No". If the user types yes, the game restarts (and this an infinite number of times, until the user has had enough of the game and ragequits xD) . I know you can do this with a loop, but how?
Excuse my lack of experience,
thanks in advance,
me.
import random print("Dice Game: try to roll a bigger number than the computer! Good luck!") print("Type 'go' to roll") dieroll = input() if dieroll == 'go': myNumber = random.randint(1,6) pcNumber = random.randint(1,6) print("You rolled " + str(myNumber)) print("He rolled " + str(pcNumber)) if myNumber < pcNumber: print("You lose!") if pcNumber < myNumber: print("You win!")