Advertisement
Guest User

Assignment 3

a guest
Feb 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.43 KB | None | 0 0
  1. #import the random module
  2. import random
  3. #create the win counters for player 1 and player 2
  4. p1WinCount = 0
  5. p2WinCount = 0
  6. #for reference "p" in a variable name means "player"
  7. #explain the function of the program
  8. print("Play the two player dice game! Make sure you have a friend to play it with.")
  9.  
  10. #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
  11. optionSelect = input("Would you like to play? (Y/N)")
  12. while optionSelect == 'Y':
  13.     #this input signals player 1 "roll", but waits until they press enter
  14.     input("Ready to roll, player 1?")
  15.  
  16.     #generate player 1's first die value
  17.     p1Roll1 = random.randint(1, 6)
  18.    
  19.     #generate player 1's second die value
  20.     p1Roll2 = random.randint(1, 6)
  21.    
  22.     #define player 1's total amount, and start it at 0
  23.     p1Total = 0
  24.  
  25.     #check if doubles were rolled
  26.     while p1Roll1 == p1Roll2:
  27.         print("Doubles! You rolled a", p1Roll1, "and a", p1Roll2)
  28.         #add player 1's total
  29.         p1Total = p1Total + p1Roll1 + p1Roll2
  30.         #tell the user to roll again
  31.         input("Get ready to roll again!")
  32.         #roll the dice again
  33.         p1Roll1 = random.randint(1, 6)
  34.         p1Roll2 = random.randint(1, 6)
  35.  
  36.     #if they dont roll a double, or they break their doubles streak, calculate their final score
  37.     print("No doubles :( You rolled a", p1Roll1, "and a", p1Roll2)
  38.     p1Total = p1Total + p1Roll1 + p1Roll2
  39.     print("Your score is:", p1Total)
  40.    
  41.     #now do the exact same thing for player 2
  42.    
  43.     #this input statement lets player 2 "roll"
  44.     input("Ready to roll, player 2?")
  45.    
  46.     #generate player 2's first die value
  47.     p2Roll1 = random.randint(1, 6)
  48.    
  49.     #generate player 2's second die value
  50.     p2Roll2 = random.randint(1, 6)
  51.    
  52.     #define player 2's total amount, and start it at 0
  53.     p2Total = 0
  54.    
  55.     #check if doubles were rolled
  56.     while p2Roll1 == p2Roll2:
  57.         print("Doubles! You rolled a", p2Roll1, "and a", p2Roll2)
  58.         #add player 2's total
  59.         p2Total = p2Total + p2Roll1 + p2Roll2
  60.         #tell the user to roll again
  61.         input("Get ready to roll again!")
  62.         #roll the dice again
  63.         p2Roll1 = random.randint(1, 6)
  64.         p2Roll2 = random.randint(1, 6)
  65.    
  66.     #if they dont roll a double, or they break their doubles streak, calculate their final score
  67.     print("No doubles :( You rolled a", p2Roll1, "and a", p2Roll2)
  68.     p2Total = p2Total + p2Roll1 + p2Roll2
  69.     print("Your score is:", p2Total)    
  70.    
  71.     #check if player 1 won and print win statement
  72.     if p1Total > p2Total:
  73.         print("Congratulations player 1, you won!")
  74.         #add 1 to their win counter
  75.         p1WinCount = p1WinCount + 1
  76.     #check if player 2 won and print win statement
  77.     elif p1Total < p2Total:
  78.         print("Congratulations player 2, you won!")
  79.         #add 1 to their win counter
  80.         p2WinCount = p2WinCount + 1
  81.     #otherwise, they must have tied, so print the tie statement
  82.     else:
  83.         print("Wow, a tie!")
  84.     #print the wincount of both players
  85.     print("Player 1 has", p1WinCount, "win(s), and player 2 has", p2WinCount, "win(s).")
  86.     #see if user wants to play again by using the optionSelect from before
  87.     optionSelect = input("Would you like to play again? (Y/N)")
  88.  
  89. #anything besides a "Y" means they do not want to play, so end the program with a message
  90. print("Thanks for playing!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement