-1

I tried to create this rock paper scissors game. But the input isn't working. Anyone know what I'm doing wrong? Every time i tried to enter input it would show think that i didnt enter anything or didn't enter a number 1-3 and go straight to else. import random

import time

y=3

while y>0:

    print("Lets play Rock Paper Scissors")
    print("1 for Rock")
    print("2 for Paper")
    print("3 for Scissors")
    time.sleep(1)
    print("Rock, Paper, Scissors...")
    var=input()
    z=random.randint(1,3)
    if z==1:
        print("I play Rock")
        time.sleep(1)
        if str(var)==1:
            print("You played Rock too! TIE")
        if str(var)==2:
            print("You played Paper! YOU WIN!!!")
        if str(var)==3:
            print("You played Scissors! I WIN!")
            y=y-1
        else:
            print("ERROR! Pick a number 1-3.")
    if z==2:
        print("I play Paper")
        time.sleep(1)
        if str(var)==1:
            print("You played Rock! I WIN!")
            y=y-1
        if str(var)==2:
            print("You played Paper too! TIE")
        if str(var)==3:
            print("You played Scissors! YOU WIN!!!")
        else:
            print("ERROR! Pick a number 1-3.")
    if z==3:
        print("I play Scissors")
        time.sleep(1)
        if str(var)==1:
            print("You played Rock! YOU WIN!!!")
        if str(var)==2:
            print("You played Paper too! I WIN!")
            y=y-1
        if str(var)==3:
            print("You played Scissors too! TIE")
        else:
            print("ERROR! Pick a number 1-3.")
    else:
        print("THIS SHOULDN'T BE POSSIBLE BUT OH WELL.... EASTER EGG")
Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

0

Your input() works fine. But you are comparing strings with integers. In each of your ifs you are comparing two different datatypes. Because "1" and 1 are not the same you program does not work.

You will have to convert the string that you get from input to a number (integer). Your ifs will have to look like:

var = input()
if int(var) == 1:
    print("You type in 1")

Or even better if you don't want to convert the variable var for each if:

var = int(input())
if var == 1:
    print("You typed 1")

For more information see: https://www.programiz.com/python-programming/variables-datatypes

itssme
  • 31
  • 1
  • 5