Created
February 14, 2016 02:06
-
-
Save NoraCodes/240fa6580b5591018e19 to your computer and use it in GitHub Desktop.
A game of pig, in Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
command = "" | |
turns = 0 | |
totalScore = 0 | |
turnScore = 0 | |
while totalScore < 25: | |
print("Turn: {} Score: {} in {} turns.".format(turnScore, totalScore, turns)) | |
command = input("command> ").lower() | |
if command == "roll": | |
roll = random.randint(1,6) | |
if roll == 1: | |
print("You rolled a 1! Poor you.") | |
turnScore = 0 | |
turns = turns + 1 | |
else: | |
#REMOVED print | |
turnScore = turnScore + roll | |
elif command == "hold": | |
print("You've ended your turn.") | |
totalScore = totalScore + turnScore | |
turnScore = 0 | |
turns = turns + 1 | |
elif command == "quit": | |
print("Bye!") | |
break; | |
else: | |
print("What?") | |
print("FINAL SCORE: {} in {} turns ({})".format(totalScore, turns, totalScore/turns)) | |
# Added for writing the score | |
if totalScore > 25: | |
name = input("Winner! Enter your name: ") | |
with open("scoreboard.txt", "w") as f: | |
f.write("{}//{}//{}\n".format(name, turns, totalScore)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment