简体   繁体   中英

how to recall random valuable from python

when I check the if condition the valuable num doesn't work. Only else work Why? please help me I don't know what to do

from random import randrange


def ran():
    num=randrange(10,99)
    print("This is your ID",num)
    stid=input("Enter Your ID ")
    if stid==num:
        print("Welcome")
    else:
        print("Sorry Try Again")
ran() 

 

Input func accepts string only and explicitly need to convert to int. Your code is comparing string with num that is reason it is always getting into else part.

from random import randrange


def ran():
    num = randrange(10, 99)
    print("This is your ID", num)
    stid = int(input("Enter Your ID "))
    if stid == num:
        print("Welcome")
    else:
        print("Sorry Try Again")


ran()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM