Ad

How To Fix Print Is Not Working In Python With The Random Lib

- 1 answer

I am creating a rock, paper, scissor game i just try the random lib but this what happens

C:\Users\Timothy\Desktop>python app1.py
2
Please choose 1=Rock, 2=Paper, 3=Siccors2

and this is the code that I create

import random
ai = (random.randint(1,3))
print(ai)
play = input("Please choose 1=Rock, 2=Paper, 3=Siccors")
if ai == play:
    print("Hello")
Ad

Answer

In Python 3, the input() method returns a string. So, play will be a string "1" and ai will be an integer 1. "1" != 1, hence your code will not execute the statements inside the if condition.

Chnage:

play = input("Please choose 1=Rock, 2=Paper, 3=Siccors")

To:

play = int(input("Please choose 1=Rock, 2=Paper, 3=Siccors"))
Ad
source: stackoverflow.com
Ad