简体   繁体   中英

smallest and largest number using 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)

i want to print smallest and largest number but im getting a error "start must be an integer on line 11" i know there will be some other mistake in my code but i want to correct this first

The arguments to range function should be plain integer documentation

You should convert to int instead of float -

halo = int(num)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM