samedi 17 mars 2018

How to use the output of randint in an if statement (Python)

I'm learning Python (3.6.3) and making a silly (and very linear) chatbot to get started. At one point the chatbot asks you to guess its age, I used randint to generate a number between 1-1000 and want to use the outputted random integer in an if statement (so the chat bot is either happy or upset by your answer, depending on whether you thought it was older than it really is). The user's input is a var called guess and I assumed (as I cannot find a similar example online) that I could just reference guess and the randint in an if statement to print the desired output, but I get an error advising radint is not defined when I run the prog -

    print('guess how old I am')
    guess = input()
    import random
    for x in range(1):
        time.sleep(0.4)
        print ('nope, I\'m ' + (str(random.randint(1,1000))) + ' actually')
        time.sleep(0.88)
    if randint <= guess 
        print('(so rude...)')
    else:
        print('aw thanks')

Apologies if my StackExchange syntax is broken too, any help appreciated, thanks




Aucun commentaire:

Enregistrer un commentaire