From fdb887e7e77f1c62d2be66d97a7049015a58c5dd Mon Sep 17 00:00:00 2001 From: Aayush61000 <91934342+Aayush61000@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:03:18 +0530 Subject: [PATCH] Create rock_paper_scissor.py --- rock_paper_scissor.py | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 rock_paper_scissor.py diff --git a/rock_paper_scissor.py b/rock_paper_scissor.py new file mode 100644 index 0000000..a2e6505 --- /dev/null +++ b/rock_paper_scissor.py @@ -0,0 +1,62 @@ + +import random +print("Winning Rules of the Rock paper scissor game as follows: \n" + +"Rock vs paper->paper wins \n" + + "Rock vs scissor->Rock wins \n" + +"paper vs scissor->scissor wins \n") + +while True: + print("Enter choice \n 1 for Rock, \n 2 for paper, and \n 3 for scissor \n") + + choice = int(input("User turn: ")) + if choice == 1: + choice_name = 'Rock' + elif choice == 2: + choice_name = 'paper' + else: + choice_name = 'scissor' + print("user choice is: " + choice_name) + print("\nNow its computer turn.......") + comp_choice = random.randint(1, 3) + while comp_choice == choice: + comp_choice = random.randint(1, 3) + if comp_choice == 1: + comp_choice_name = 'Rock' + elif comp_choice == 2: + comp_choice_name = 'paper' + else: + comp_choice_name = 'scissor' + + print("Computer choice is: " + comp_choice_name) + + print(choice_name + " V/s " + comp_choice_name) + if choice == comp_choice: + print("Draw=> ", end = "") + result = Draw + + if((choice == 1 and comp_choice == 2) or + (choice == 2 and comp_choice ==1 )): + print("paper wins => ", end = "") + result = "paper" + + elif((choice == 1 and comp_choice == 3) or + (choice == 3 and comp_choice == 1)): + print("Rock wins =>", end = "") + result = "Rock" + else: + print("scissor wins =>", end = "") + result = "scissor" + + if result == Draw: + print("<== Its a tie ==>") + if result == choice_name: + print("<== User wins ==>") + else: + print("<== Computer wins ==>") + + print("Do you want to play again? (Y/N)") + ans = input().lower + + if ans == 'n': + break +print("\nThanks for playing")