Time.sleep()错误

时间:2017-12-13 13:18:50

标签: python

所以time.sleep不起作用。我在python 3.4.3上,我的计算机上没有这个问题3.6。

这是我的代码:

import calendar

def ProfileCreation():
    Name = input("Name: ")
    print("LOADING...")
    time.sleep(1)
    Age = input("Age: ")
    print("LOADING...")
    time.sleep(1)
    ProfileAns = input("This matches no profiles. Create profile? ")
    if ProfileAns.lower == 'yes':
        print("Creating profile...")
    elif ProfileAns.lower == 'no':
        print("Creating profile anyway...")
    else:
        print("yes or no answer.")
        ProfileCreation()
ProfileCreation()

3 个答案:

答案 0 :(得分:2)

您可能希望import time目前time.sleep(1)尚未实际定义,只需将导入添加到代码顶部即可解决此问题。

答案 1 :(得分:0)

将其更改为以下内容:

import calendar
import time
def ProfileCreation():
    Name = input("Name: ")
    print("LOADING...")
    time.sleep(1)
    Age = input("Age: ")
    print("LOADING...")
    time.sleep(1)
    ProfileAns = input("This matches no profiles. Create profile? ")
    if ProfileAns.lower == 'yes':
        print("Creating profile...")
    elif ProfileAns.lower == 'no':
        print("Creating profile anyway...")
    else:
        print("yes or no answer.")
        ProfileCreation()
ProfileCreation()

答案 2 :(得分:0)

在导入语句中,您已导入日历,您也应导入时间。睡觉是在时间包内。     导入日历     进口时间

def ProfileCreation():
    Name = input("Name: ")
    print("LOADING...")
    time.sleep(1)
    Age = input("Age: ")
    print("LOADING...")
    time.sleep(1)
    ProfileAns = input("This matches no profiles. Create profile? ")
    if ProfileAns.lower == 'yes':
        print("Creating profile...")
    elif ProfileAns.lower == 'no':
        print("Creating profile anyway...")
    else:
        print("yes or no answer.")
        ProfileCreation()
ProfileCreation()