Hi,
Am new to python programming, one of the problems am working is resulting in incorrect results, can someone please help me on it.
Appreciate your help!!!
Q: Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'.
Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number.
Input Example is 7, 2, bob, 10, and 4
Below is my code:
Am new to python programming, one of the problems am working is resulting in incorrect results, can someone please help me on it.
Appreciate your help!!!
Q: Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'.
Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number.
Input Example is 7, 2, bob, 10, and 4
Below is my code:
largest = None
smallest = None
while True:
try:
num = input("Enter a number: ")
if num == "done" :
break
print(num)
for i_num in num :
if i_num > largest :
largest = i_num
print('largest',i_num)
else :
for i_num in num :
if smallest is None:
smallest = i_num
elif i_num < smallest:
smallest=i_num
print('smallest',i_num)
print("Maximum", largest)
print("Minimum",smallest)
except:
if i_num == 'bob':
print("Invalid Input",i_num)
#continue
print("Maximum", largest)
print("Minimum",smallest)
