Cannot Use Time.Sleep In Python

689 Views Asked by At

I'm trying to make a login for a text-based OS in Python

I have tried to import time and time.sleep but it still doesn't work.

import time
usrname = str(input("What Is Your Username? "))
age = str(input("What Is You Age"))
print("Welcome",usrname)

if age <= 1:
    print ("That`s An Invalid Age!")
    time.sleep(3)

I don't see any errors because it's so fast it closes in 1/2 a second.

1

There are 1 best solutions below

2
Green Cloak Guy On

The condition if age <= 1: is never going to be triggered, because age is a string. As a result, the time.sleep() statement within the if block is never going to run.

In order for the conditional to work, you need to make age an int (perhaps by doing if int(age) <= 1:).