Reference no: EM132382389
Question
#Print the welcome message and menu list
print("Welcome to the Python Calculator Application.")
print("Addition or Subtraction ")
print("1) Addition (+)")
print("2) Subtraction (-)")
#Take user choice
userChoice = input("Enter 1 or 2 indicating your selection.")
#Check if user choice is addition
if(userChoice == "1"):
print("Addition was selected.")
first = int(input("Enter your first integer:"))
second = int(input("Enter your second integer:"))
print("Addition of "+str(first)+" and "+str(second)+" is : "+str(first+second))
#Check if user choice is Subtraction
elif(userChoice=="2"):
print("Subtraction was selected.")
first = int(input("Enter your first integer:"))
second = int(input("Enter your second integer:"))
print("Difference of "+str(first)+" and "+str(second)+" is : "+str(first-second))
while True:
try:
NUM1 = int(input("Please enter the first integer.n"))
NUM2 = int(input("Please enter the second integer.n"))
break
except ValueError:
print('Please enter a whole number')
print("nThe smallest number is " + str(min(int(NUM1), int(NUM2))))
print("The largest number is " + str(max(int(NUM1), int(NUM2))))
print("nProgram finished.")
Use one or more python validation techniques provided and fix your code to gracefully and securely handle user input errors.
Just pick a smaller section of the code to fix. Provide the code before and after the fix. Be sure to demonstrate the new fix works as expected by providing screen captures.