Python Forum

Full Version: Coursera python for everybody 5.2 assignment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
l = 0
s = 1000000
while True:
    num = input("Enter a number: ")
    if num == "done": break
    try: n = int(num)
    except: print('Invalid input')
    if n > l: l = n
    if n < s: s = n
    continue

print("Maximum is", l)
print("Minimum is", s)
I expect that this is what you are looking for:
while True:
    num = input("Enter a number: ")
    if num == "done":
        break
    try:
        n = int(num)
    except ValueError:
        print('Invalid input')
        continue
    if n > l:
        l = n
    if n < s:
        s = n
Note: it is recommended that conditions go on one line, and solution indented underneath.
Also, use specific except condition, or others will be ignored.
Pages: 1 2