largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num == "done" : break
try:
halo = float(num)
except:
print("invalid output")
continue
for largest in range(halo):
if largest is None:
largest = halo
elif largest > halo:
largest = halo
for smallest in range(halo):
if smallest is None:
smallest = halo
elif smallest<halo:
smallest = halo
print("largest is",largest)
print("smallest is",smallest)
我想打印最小和最大的数字,但我得到一个错误“start must be a integer on line 11” 我知道我的代码中会有其他错误,但我想先更正这个错误
range
函数的参数应为普通整数documentation您应该转换为
int
,而不是float
-相关问题 更多 >
编程相关推荐