概述
当我在生成一个变量并将while设置为True、try/except命令后尝试返回值时,该变量不返回该值。我正在努力使这个“起点”全球化,以便可以使用它。在def start_time():
while True:
try:
starting = int(input("Please enter a starting hour(HH): "))
if starting < 0:
print("There are no negative hours!")
elif starting > 24:
print("There are only 24 hours in a day!")
else:
break
except ValueError:
print("Please enter in a correct format (HH)")
return starting
def end_time():
while True:
try:
ending = int(input("Please enter an ending hour (HH): "))
if ending < starting:
print("You can only plan a day!")
elif ending < 0:
print("There are only 24 hours in a day!")
elif ending > 24:
print("There are only 24 hours in a day!")
else:
break
except ValueError:
print("Please enter in a correct format (HH)")
return ending
#obtain starting and ending time
start_time()
end_time()
#confirm starting and ending time
谢谢
最后
以上就是善良老师为你收集整理的python while true try except_Python为true时,Try/Except,返回valu的全部内容,希望文章能够帮你解决python while true try except_Python为true时,Try/Except,返回valu所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复