|
40 | 40 | # among 1 , 2 and 3. Using randint method |
41 | 41 | # of random module |
42 | 42 | comp_choice = random.randint(1, 3) |
43 | | - |
44 | | - # looping until comp_choice value |
45 | | - # is equal to the choice value |
46 | | - while comp_choice == choice: |
47 | | - comp_choice = random.randint(1, 3) |
48 | | - |
49 | | - # initialize value of comp_choice_name |
50 | | - # variable corresponding to the choice value |
51 | | - if comp_choice == 1: |
52 | | - comp_choice_name = 'Rock' |
53 | | - elif comp_choice == 2: |
54 | | - comp_choice_name = 'Paper' |
55 | | - else: |
56 | | - comp_choice_name = 'Scissor' |
| 43 | + #check for draw |
| 44 | + if comp_choice == choice: |
| 45 | + print("We both choose "+choice_name) |
| 46 | + print(" - It´s a draw") |
| 47 | + else: |
| 48 | + # initialize value of comp_choice_name |
| 49 | + # variable corresponding to the choice value |
| 50 | + if comp_choice == 1: |
| 51 | + comp_choice_name = 'Rock' |
| 52 | + elif comp_choice == 2: |
| 53 | + comp_choice_name = 'Paper' |
| 54 | + else: |
| 55 | + comp_choice_name = 'Scissor' |
57 | 56 |
|
58 | | - print("I did choose: " + comp_choice_name) |
| 57 | + print("I did choose: " + comp_choice_name) |
59 | 58 |
|
60 | | - print(choice_name + " V/s " + comp_choice_name) |
| 59 | + print(choice_name + " V/s " + comp_choice_name) |
61 | 60 |
|
62 | | - # condition for winning |
63 | | - if((choice == 1 and comp_choice == 2) or |
64 | | - (choice == 2 and comp_choice ==1 )): |
65 | | - print("Paper wins => ", end = "") |
66 | | - result = "Paper" |
| 61 | + # condition for winning |
| 62 | + if((choice == 1 and comp_choice == 2) or |
| 63 | + (choice == 2 and comp_choice ==1 )): |
| 64 | + print("Paper wins => ", end = "") |
| 65 | + result = "Paper" |
67 | 66 |
|
68 | | - elif((choice == 1 and comp_choice == 3) or |
69 | | - (choice == 3 and comp_choice == 1)): |
70 | | - print("Rock wins =>", end = "") |
71 | | - result = "Rock" |
72 | | - else: |
73 | | - print("Scissor wins =>", end = "") |
74 | | - result = "Scissor" |
| 67 | + elif((choice == 1 and comp_choice == 3) or |
| 68 | + (choice == 3 and comp_choice == 1)): |
| 69 | + print("Rock wins =>", end = "") |
| 70 | + result = "Rock" |
| 71 | + else: |
| 72 | + print("Scissor wins =>", end = "") |
| 73 | + result = "Scissor" |
75 | 74 |
|
76 | | - # Printing either user or computer wins |
77 | | - if result == choice_name: |
78 | | - print("<== User wins ==>") |
79 | | - else: |
80 | | - print("<== Computer wins ==>") |
| 75 | + # Printing either user or computer wins |
| 76 | + if result == choice_name: |
| 77 | + print("<== User wins ==>") |
| 78 | + else: |
| 79 | + print("<== Computer wins ==>") |
81 | 80 |
|
82 | 81 | print("Do you want to play again? (Y/N)") |
83 | 82 | ans = input() |
|
0 commit comments