I am learning python from scratch. I have written one small code for a rock paper scissor game. where 1 input is from the user and another input from PC using the random library. I know my code is not perfect. but I am not understanding one thing when I was trying to test my code.
Here is my code.
import random
from time import sleep
print("Let's play the game")
print("For Rock Choose 1")
print("For Paper Choose 2")
print("For Scissors Choose 3")
a = int(input("Enter the number "))
if a == 1:
print("You Choose Rock")
elif a == 2:
print("You Choose Paper")
elif a == 3:
print("You Chosse Scissors")
else:
print("Invalid Input")
print ("Now taking input from PC")
sleep (3)
b = random.randint(1,3)
if b == 1:
print("PC has given Rock")
elif b == 2:
print ("PC has given Paper")
elif b==3:
print ("PC has given Scissors")
if a == b:
print ("Match Tie")
elif a ==1 & b == 3:
print ("You Win")
elif a == 2 & b == 1:
print ("You Win")
elif a == 3 & b == 2:
print ("You Win")
else:
print ("You Loose")
You can clearly see i choose 2 and PC choose 1. then the output i got is "You Loose" how it can possible in condition i clearly written if a == 2 & b == 1 print ("You Win")
While testing this code (selected code of image) I found one thing and I got confused.