当用户留下错误的格式输入时如何通知错误?
How to inform error when user leaving wrong format input?
当用户按要求输入非整数时,如何提示错误?
例如:
number = int(input("Input the number: "))
我想编写如下代码:如果数字“不是”整数,那么
if number is not integers
print("The input was not numerical value. Please try again")
else:
print ("Input "+ str(number) + " elements in the list:")
你能帮帮我吗
谢谢!
try/except 语句应该很合适:
try:
number = int(input("Input the number: "))
print ("Input "+ str(number) + " elements in the list:")
except ValueError:
print("The input was not numerical value. Please try again")
当用户按要求输入非整数时,如何提示错误?
例如:
number = int(input("Input the number: "))
我想编写如下代码:如果数字“不是”整数,那么
if number is not integers
print("The input was not numerical value. Please try again")
else:
print ("Input "+ str(number) + " elements in the list:")
你能帮帮我吗
谢谢!
try/except 语句应该很合适:
try:
number = int(input("Input the number: "))
print ("Input "+ str(number) + " elements in the list:")
except ValueError:
print("The input was not numerical value. Please try again")