i have created this code which would take the input from the user and remove the largest and the smallest number from the input but it doesn’t seem to work. I do get the largest value but not the minimum one. Please help.
largest = None
smallest = None
while True:
inp = raw_input("Enter a number: ")
#Cases
if inp == "done" : break
#Work over here
try:
num = int(inp)
except:
print "Invalid input"
continue
if smallest is None:
smallest = num
elif num < smallest:
smallest = num
if largest is None:
largest = num
elif num > largest:
largest = num
print “Maximum is”, largest
print “Minimum is”, smallest
@designninja71844,
list=[]
while True:
try:
ans = raw_input("Select a monitoring plot from the list: ")
if ans == 'q':
break
ans = int(ans)
list.append(ans)
except ValueError:
print "Error: Please enter a number between 0 and 9"
print list
#list=[1,2.0,'b',3,4,5,0,'a']
cln_list=[]
for elemnt in list:
print str(type(elemnt))+"="
if str(type(elemnt)) == "<type 'int'>" or str(type(elemnt)) == "<type 'float'>":
cln_list.append(elemnt)
print cln_list
print "Maximum: " + str(max(cln_list))
print "Minimum: " + str(min(cln_list))
Reference:
google search
== the Book ==
[your question] site:python.org
== discussions / opinions ==
[your question] site:stackoverflow.com