【发布时间】:2020-07-28 03:56:58
【问题描述】:
我正在制作一个程序,它可以根据输入的时间告诉一天中的哪个部分。
我的代码:
user_day = input("What's the time? ")
if user_day >= 20 and user_day <= 24:
day_time = "Night"
elif user_day >= 24 and user_day <= 12:
day_time = "Morning"
elif user_day >= 12 and user_day >= 17:
day_time = "Noon"
elif user_day >= 17 and user_day >= 20:
day_time = "Evening"
但我收到此错误:
if day_time == 1 and user_weather == plus:
NameError: name 'day_time' is not defined
请帮帮我。
【问题讨论】:
-
这个错误代码相对于代码的
if user_day...部分在哪里?
标签: python python-3.x if-statement nameerror