【发布时间】:2022-11-14 06:18:17
【问题描述】:
def arithmetic_sequence():
a = float(input('Type the first term'))
d = float(input('Type the difference'))
n = float(input("Type the number of values"))
if a == ValueError:
print("Write a value")
elif d == ValueError:
print("Write a value")
elif n == ValueError:
print("Write a value")
else:
sum = float(n * (a + (a + d * (n - 1))) / 2)
return sum
print(arithmetic_sequence())
我的目标是当一个人在程序中写入一个非数字让它说写一个值但它只显示ValueError,为什么?我专门在程序中写了“键入一个值”。
【问题讨论】:
-
您实际上根本没有进行任何错误处理,请查看
try/exceptpythonbasics.org/try-except
标签: python python-3.x