Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def numberToName(number):
- # Implement Function
- if number == 1:
- ("replace print with retun")
- return("rock")
- elif number == 2:
- return("paper")
- elif number == 3:
- return("scissors")
- elif number == -1:
- return "quit"
- def rockPaperScissors():
- Player1 = int(input())
- Player2 = random.randint(0,3)
- Player1_S = numberToName(Player1)
- Player2_S = numberToName(Player2)
- print("Player1 " + str(Player1_S))
- print("Player2 " + str(Player2_S))
- if Player1 == -1:
- return(False)
- elif Player1_S == Player2_S:
- return ("T")
- elif Player1_S == "rock":
- if Player2_S == "paper":
- return ("L")
- else:
- return("W")
- elif Player1_S == "paper":
- if Player2_S == "scissors":
- return ("L")
- else:
- return ("W")
- elif Player1_S == "scissors":
- if Player2_S == "rock":
- return("L")
- else:
- return ("W")
- def countLetters(word, char):
- count = 0
- for i in word:
- if i == char:
- count += 1
- return (count)
- if __name__ == '__main__':
- userInput = 0
- while userInput != -1:
- print("\nPlease select one of the menu options")
- print(" 1. Start game of rock, paper, scissors")
- print("-1. to exit the program.")
- userInput = input()
- if (userInput == '1'):
- print('\nStarting Game... Input 1 for rock, 2 for paper or 3 for scissor.\n')
- matchHistory = []
- a = True
- while (a):
- result = rockPaperScissors()
- matchHistory.append(result)
- if countLetters(matchHistory, 'W') == 2:
- print ("Player1 wins 2 out of 3")
- break
- elif countLetters(matchHistory, 'L') == 2:
- print ("Player2 wins 2 out 3")
- break
- elif result == False:
- break
- #
- elif (userInput == '-1'):
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement