dicegame
unknown
python
4 years ago
791 B
12
Indexable
import sys
import random
playagain = True
score = 0
while playagain:
a = random.randint(1, 6)
b = random.randint(1, 6)
print(a)
print(b)
if (a == 1) & (b == 1):
score = 0
print("game over. score: " + str(score))
break
if a + b == 7:
score = 0
print("game over. score: " + str(score))
break
if a == b:
score = score + 2*(a+b)
print("score: " + str(score))
playagain = True # must play again
else:
score = score + (a + b)
msg = "Your score is " + str(score) + " . Play again? (y/n): "
playagain = input(msg) # user can decide to play or stop
playagain = playagain == "y" # convert to boolean
# strategy 1: always play N games then stop asap
# strategy 2: always play until i get a score of X then stop asap
Editor is loading...