Skip to content

Instantly share code, notes, and snippets.

@JokubasR
Last active July 10, 2018 11:11
Show Gist options
  • Save JokubasR/c1baae6d8d569ecd6928c2d64e62dfb6 to your computer and use it in GitHub Desktop.
Save JokubasR/c1baae6d8d569ecd6928c2d64e62dfb6 to your computer and use it in GitHub Desktop.
import random
def rollDice():
print("Rolling dice...")
return random.randint(1, 6)
def awardPlayer(tries):
global availableTickets
award = guessesPerGame - tries + 1
availableTickets += award
print("You have been awarded with ", award, " additional tickets!")
print("Now in total you have ", availableTickets, " tickets")
def getUserGuess():
global availableTickets
availableTickets -= 1
return int(input("Take a guess: "))
guessesPerGame = 3
availableTickets = 3
while availableTickets > 0:
diceValue = rollDice();
availableTicketsPerGame = min(guessesPerGame, availableTickets)
print("\nDice is rolled! You have", availableTicketsPerGame, " tickets for this game. Let's common!\n")
tries = 0
hasWonGame = False
while not hasWonGame and tries < availableTicketsPerGame:
tries += 1
guess = getUserGuess()
if guess == diceValue:
print("Success! Your answer is correct!")
awardPlayer(tries)
hasWonGame = True
else:
print("Errrr..... Try again!")
if not hasWonGame:
if availableTickets > 0:
print("You are out of tickets for this game. Try once again!")
else:
print("You are out of tickets! The end.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment