代码拉取完成,页面将自动刷新
def get_user_input(start, end):
"""
input: two integer values
lower limit 'start' and maximum 'end'
the arguments aren't inclusive.
output: if reading successful then returns the read integer.
purpose: reads from command-line a integer in the given bounds.
while input invalid asks user again
"""
loop = True # controls while-loop
while loop:
try:
# reads and converts the input from the console.
user_input = int(input("Enter Your choice: "))
# checks whether input is in the given bounds.
if user_input > end or user_input < start:
# error case
print("Please try again. Not in valid bounds.")
else:
# valid case
loop = False # aborts while-loop
except ValueError:
# error case
print("Please try again. Only numbers")
return user_input
x = get_user_input(1, 6)
print(x)
# Asks user to enter something, ie. a number option from a menu.
# While type != interger, and not in the given range,
# Program gives error message and asks for new input.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。