Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import the random module
- import random
- #create the win counters for player 1 and player 2
- p1WinCount = 0
- p2WinCount = 0
- #for reference "p" in a variable name means "player"
- #explain the function of the program
- print("Play the two player dice game! Make sure you have a friend to play it with.")
- #this begins the loop. The reason it asks for a (Y/N) is so I can use that same option to break the loop if they dont want to play
- optionSelect = input("Would you like to play? (Y/N)")
- while optionSelect == 'Y':
- #this input signals player 1 "roll", but waits until they press enter
- input("Ready to roll, player 1?")
- #generate player 1's first die value
- p1Roll1 = random.randint(1, 6)
- #generate player 1's second die value
- p1Roll2 = random.randint(1, 6)
- #define player 1's total amount, and start it at 0
- p1Total = 0
- #check if doubles were rolled
- while p1Roll1 == p1Roll2:
- print("Doubles! You rolled a", p1Roll1, "and a", p1Roll2)
- #add player 1's total
- p1Total = p1Total + p1Roll1 + p1Roll2
- #tell the user to roll again
- input("Get ready to roll again!")
- #roll the dice again
- p1Roll1 = random.randint(1, 6)
- p1Roll2 = random.randint(1, 6)
- #if they dont roll a double, or they break their doubles streak, calculate their final score
- print("No doubles :( You rolled a", p1Roll1, "and a", p1Roll2)
- p1Total = p1Total + p1Roll1 + p1Roll2
- print("Your score is:", p1Total)
- #now do the exact same thing for player 2
- #this input statement lets player 2 "roll"
- input("Ready to roll, player 2?")
- #generate player 2's first die value
- p2Roll1 = random.randint(1, 6)
- #generate player 2's second die value
- p2Roll2 = random.randint(1, 6)
- #define player 2's total amount, and start it at 0
- p2Total = 0
- #check if doubles were rolled
- while p2Roll1 == p2Roll2:
- print("Doubles! You rolled a", p2Roll1, "and a", p2Roll2)
- #add player 2's total
- p2Total = p2Total + p2Roll1 + p2Roll2
- #tell the user to roll again
- input("Get ready to roll again!")
- #roll the dice again
- p2Roll1 = random.randint(1, 6)
- p2Roll2 = random.randint(1, 6)
- #if they dont roll a double, or they break their doubles streak, calculate their final score
- print("No doubles :( You rolled a", p2Roll1, "and a", p2Roll2)
- p2Total = p2Total + p2Roll1 + p2Roll2
- print("Your score is:", p2Total)
- #check if player 1 won and print win statement
- if p1Total > p2Total:
- print("Congratulations player 1, you won!")
- #add 1 to their win counter
- p1WinCount = p1WinCount + 1
- #check if player 2 won and print win statement
- elif p1Total < p2Total:
- print("Congratulations player 2, you won!")
- #add 1 to their win counter
- p2WinCount = p2WinCount + 1
- #otherwise, they must have tied, so print the tie statement
- else:
- print("Wow, a tie!")
- #print the wincount of both players
- print("Player 1 has", p1WinCount, "win(s), and player 2 has", p2WinCount, "win(s).")
- #see if user wants to play again by using the optionSelect from before
- optionSelect = input("Would you like to play again? (Y/N)")
- #anything besides a "Y" means they do not want to play, so end the program with a message
- print("Thanks for playing!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement