Home > front end >  why is my python if statement is not working
why is my python if statement is not working

Time:04-23

so im pretty sure everything is correct but here it is not working, I would really apperciate it if someone could help me, this code is meant to make you choose between 3 doors, and after you choose a door, it will tell you a door that it is not it also that is not the door that you choose, finally this last part is meant to print the code

import random
import time

prize = (random.randint(1,3))
randomDoor = 7
question = 0



door = input ("Choose a door: 1, 2, ou 3")

print ("you chose door...", door)


#########               PRIZE IS 1                  ################################
if (prize == 1 and door == 1):
        print("random door = 3")
        randomDoor = 3

if (prize == 1 and door == 2):
        randomDoor = 3
        
if (prize == 1 and door == 3):
        randomDoor = 2
        

#################               PRIZE IS 2             #############################
if (prize == 2 and door == 1):
        randomDoor = 3

if (prize == 2 and door == 2):
        randomDoor = 3

if (prize == 2 and door == 3):
        randomDoor = 1
        
####################        PRIZE IS 3              ##############################
if (prize == 3 and door == 1):
        randomDoor = 2
        
if (prize == 3 and door == 2):
        randomDoor = 1

if (prize == 3 and door == 3):
        randomDoor = 1




print (randomDoor, "has nothing in it")
    

CodePudding user response:

import random


prize = (random.randint(1,3))
randomDoor = 7
question = 0



door = int(input ("Choose a door: 1, 2, ou 3"))

print ("you chose door...", door)


#########               PRIZE IS 1                  ################################
if (prize == 1 and door == 1):
        print("random door = 3")
        randomDoor = 3

if (prize == 1 and door == 2):
        randomDoor = 3
        
if (prize == 1 and door == 3):
        randomDoor = 2
        

#################               PRIZE IS 2             #############################
if (prize == 2 and door == 1):
        randomDoor = 3

if (prize == 2 and door == 2):
        randomDoor = 3

if (prize == 2 and door == 3):
        randomDoor = 1
        
####################        PRIZE IS 3              ##############################
if (prize == 3 and door == 1):
        randomDoor = 2
        
if (prize == 3 and door == 2):
        randomDoor = 1

if (prize == 3 and door == 3):
        randomDoor = 1




print (randomDoor, "has nothing in it")

changes :

door = int(input ("Choose a door: 1, 2, ou 3"))

When you get an input, if you do not specify its type, it is a string by default

  • Related