You are the governer of Neverland and is being given a task to report the census of the people is its country. You already have a software that does the same. The input is taken from the user but the input is not validated correctly. A user can enter digits in input but the state name can never have digits. The code breaks in such inputs. Write a code that handles this exception gracefully. You are given the input module of the codebase.
Enter the state name
Digit entered in state name. Exiting gracefully
Muscle Puma is creating an online shoe store that lets user give the shoe size and orders the same shoe. As this is a budding start up, the code is only supposed to handle integers as of now and will handle the float functionality later. Muscle Puma wants to let the input come in float but wants it to be rounded to nearest integer. He was already raising the exception in case float was entered. You don’t want to change the current code and instead want to add a wrapper on top of it to.
Please enter your shoe size
Changing the size to int
The new shoe size is 5
Ghost Fly is a final semester computer science student and writes a program that calculates the area of a triangle as a final project. He gets the input from user and gets the sides as space separated integers. He wants this to be tested before giving a demo in his class and hence writes a exception handler that checks that 3 sides are entered. If not, prmpt the user to run the code again. Write the program for him.
def calculate_area(side1, side2, side3):
sides = sys.argv[1:]
global side1, side2, side3
side1 = int(sides)
side2 = int(sides)
side3 = int(sides)
print('3 values were not entered')
calculate_area(side1, side2, side3)
# To run the program
c:/> python area_of_triangle.py 34 53
3 values were not entered