Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated pig.py into a function #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 25 additions & 32 deletions pig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,42 @@
turn = "player"
winning_score = 50

while not done:
def play(turn, done, player_temp_total, player_total):
while turn == "player" and not done:
print()
print("Player:", player_total, "Computer:", comp_total)
print("It's your turn!")
print("It's ", turn, " turn!")
roll = random.randint(1,6)
print("You rolled a", roll)
print(turn, " rolled a", roll)
if roll == 1:
turn = "computer"
if(turn == "player"):
turn = "computer"
else:
turn = "player"
player_temp_total = 0
print("PIG! Too bad! Your total is currently:", player_total)
else:
player_temp_total += roll
print("You currently have " + str(player_temp_total) + " banked.")
choice = input("Do you wish to roll again (y/n)?: ")
if choice == 'n':
player_total += player_temp_total
player_temp_total = 0
print("Your total socre is now:", player_total)
turn = "computer"
if(turn == "player"):
choice = input("Do you wish to roll again (y/n)?: ")
if choice == 'n':
player_total += player_temp_total
player_temp_total = 0
print("Your total socre is now:", player_total)
turn = "computer"
else:
if player_temp_total > 6 or player_total + player_temp_total > winning_score:
print("The computer has chosen to end its turn.")
player_total += player_temp_total
player_temp_total = 0
print("The computer's score is now:", player_total)
turn = "player"
if player_total > winning_score:
print("You win! " + str(player_total) + " to " + str(comp_total))
done = True

while turn == "computer" and not done:
print()
print("Player:", player_total, "Computer:", comp_total)
print("It's the computer's turn!")
roll = random.randint(1,6)
print("The computer rolled a", roll)
if roll == 1:
turn = "player"
comp_temp_total = 0
print("PIG! Too bad! The computer's total is currently:", comp_total)
else:
comp_temp_total += roll
print("The computer has " + str(comp_temp_total) + " banked.")
if comp_temp_total > 6 or comp_total + comp_temp_total > winning_score:
print("The computer has chosen to end its turn.")
comp_total += comp_temp_total
comp_temp_total = 0
print("The computer's score is now:", comp_total)
turn = "player"
if comp_total > winning_score:
print("The computer wins! " + str(comp_total) + " to " + str(player_total))
done = True
while not done:
play(turn, done, player_temp_total, player_total)
play(turn, done, comp_temp_total, comp_total)
done = True