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

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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))