使用python

时间:2015-06-24 10:24:57

标签: python

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必须是第11行的整数” 我知道我的代码中会有其他错误,但我想先纠正这个错误

1 个答案:

答案 0 :(得分:1)

range函数的参数应为普通整数documentation

您应该转换为int而不是float -

halo = int(num)