我是靠谱客的博主 善良老师,这篇文章主要介绍python while true try except_Python为true时,Try/Except,返回valu,现在分享给大家,希望可以做个参考。

当我在生成一个变量并将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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(122)

评论列表共有 0 条评论

立即
投稿
返回
顶部