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

0

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))
Posted by: Guest on July-03-2020

Code answers related to "python ask for real values until negative value diplay highest and lowest"

Python Answers by Framework

Browse Popular Code Answers by Language