I'm new to Python (or any coding really) and need to return max and min values from array entered by user. I can get it to return the max no problem, but min gives me <unknown>
message back. Can anybody help me fix the code for my min return? Thanks.
Here is my code:
maximum = None
minimum = None
while True:
#enter the input
inp = raw_input("Enter a number:")
#handle the edge cases
if inp == "done" :
break
if len(inp) < 1 :
break
#only accept good input
try:
num = int(inp)
#print num
except:
print "Invalid input"
continue
#do the work
if num > maximum :
max = num
if num < minimum :
min = num
else:
num
print "Maximum is", max
print "Minimum is", min
None
, so the linemin = num
is never run. – Jared Goguenmin
is a built-in, so it prints that. – Jared Goguen