python ask for real values until negative value diplay highest and lowest code example
Example: python ask for real values until negative value diplay highest and lowest
print "Enter numbers, stops when negative value is entered:"
nums = []
while True: # infinite loop
try: n = int(raw_input("Enter a number: ")) # raw_input returns a string, so convert to an integer
except ValueError:
n = -1
print "Not a number!"
if n < 0: break # when n is negative, break out of the loop
else: nums.append(n)
print "Maximum number: {}".format(max(nums))