Skip to content

Instantly share code, notes, and snippets.

@rasel-rz
Last active May 11, 2020 19:08
Show Gist options
  • Save rasel-rz/896c752a4d91036ba64461d3580333d0 to your computer and use it in GitHub Desktop.
Save rasel-rz/896c752a4d91036ba64461d3580333d0 to your computer and use it in GitHub Desktop.
# Score starts with zero.
scores = [300, 500, 500, 0, 600]
lives = 3 # Default 3 lives
# Game state negative means means Start Menu
# Positive means Playing
gameState = 0
print("Playing")
for score in scores:
if lives is 0:
print("Game over! You lose.")
break
else:
print(score, end=" - ")
if(gameState >= 0):
# If score is in between a level i.e. 1-499, 501-999, 1001-1499 etc, its a loose
# % (called Modulus) gives you Remainder of a division.
if(score % 500 > 0 and score % 500 < 500):
print("Lose")
lives = lives - 1
else:
print("Win")
lives = lives + 1
if lives > 0:
print("Congrats! You finished the game.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment