Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def numberToName(number):
  5.     # Implement Function
  6.     if number == 1:
  7.         ("replace print with retun")
  8.         return("rock")
  9.     elif number == 2:
  10.        return("paper")
  11.     elif number == 3:
  12.         return("scissors")
  13.     elif number == -1:
  14.         return "quit"
  15.  
  16. def rockPaperScissors():
  17.     Player1 = int(input())
  18.     Player2 = random.randint(0,3)
  19.     Player1_S = numberToName(Player1)
  20.     Player2_S = numberToName(Player2)
  21.     print("Player1 " + str(Player1_S))
  22.     print("Player2 " + str(Player2_S))
  23.  
  24.     if Player1 == -1:
  25.         return(False)
  26.     elif Player1_S == Player2_S:
  27.         return ("T")
  28.     elif Player1_S == "rock":
  29.         if Player2_S == "paper":
  30.             return ("L")
  31.         else:
  32.             return("W")
  33.     elif Player1_S == "paper":
  34.         if Player2_S == "scissors":
  35.             return ("L")
  36.         else:
  37.             return ("W")
  38.     elif Player1_S == "scissors":
  39.         if Player2_S == "rock":
  40.             return("L")
  41.         else:
  42.             return ("W")
  43.  
  44.  
  45.  
  46.  
  47. def countLetters(word, char):
  48.     count = 0
  49.     for i in word:
  50.         if i == char:
  51.             count += 1
  52.     return (count)
  53.  
  54.  
  55. if __name__ == '__main__':
  56.     userInput = 0
  57.  
  58.     while userInput != -1:
  59.         print("\nPlease select one of the menu options")
  60.         print(" 1. Start game of rock, paper, scissors")
  61.         print("-1. to exit the program.")
  62.  
  63.         userInput = input()
  64.         if (userInput == '1'):
  65.             print('\nStarting Game... Input 1 for rock, 2 for paper or 3 for scissor.\n')
  66.             matchHistory = []
  67.             a = True
  68.             while (a):
  69.                 result = rockPaperScissors()
  70.  
  71.                 matchHistory.append(result)
  72.                 if countLetters(matchHistory, 'W') == 2:
  73.                     print ("Player1 wins 2 out of 3")
  74.                     break
  75.                 elif countLetters(matchHistory, 'L') == 2:
  76.                     print ("Player2 wins 2 out 3")
  77.                     break
  78.                 elif result == False:
  79.                     break
  80.                 #
  81.  
  82.         elif (userInput == '-1'):
  83.             break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement