python ask for real values until negative value diplay highest and lowest

Solutions on MaxInterview for python ask for real values until negative value diplay highest and lowest by the best coders in the world

showing results for - "python ask for real values until negative value diplay highest and lowest"
Amaryllis
27 May 2016
1print "Enter numbers, stops when negative value is entered:"
2nums = []
3while True: # infinite loop
4    try: n = int(raw_input("Enter a number: ")) # raw_input returns a string, so convert to an integer
5    except ValueError: 
6        n = -1
7        print "Not a number!"
8    if n < 0: break # when n is negative, break out of the loop
9    else: nums.append(n)
10print "Maximum number: {}".format(max(nums))