dimanche 10 juillet 2016

Beginner Python Code Issues

5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter the numbers from the book for problem 5.1 and Match the desired output as shown.

Here is my Code:

largest = None
smallest = None
while True:
    inp = raw_input("Enter a number: ")
    if inp == "done" : break
    try:
        num = float(inp)
    except:
        print "Invalid input"
    if smallest is None:
        smallest = num
    elif num < smallest:
        smallest = num
    elif num > largest:
        largest = num

    continue

print "Maximum is", largest
print "Minimum is", smallest

******Please let me know the Logic errors in this CODE*****

Aucun commentaire:

Enregistrer un commentaire