【发布时间】:2021-05-01 02:58:25
【问题描述】:
def tryexcept(variable,range1,range2):
while variable not in range(range1,range2):
try:
if variable not in range(range1,range2):
variable = int(input("Enter your decision \033[95m(1)\033[0m or \033[95m(2)\033[0m"))
# Making the options stand out with \033[95m for error prevention, plus it looks nice
except:
print("Not valid please enter an intiger \033[95m(1 or 2)\033[0m")
menu_option = 0
tryexcept(menu_option,1,3)
我尝试了全局变量并更改了变量的定义顺序
【问题讨论】:
-
你的函数返回什么?
标签: python exception while-loop global-variables try-catch