from math import *
print("Calculator that performs simple arithmetic with 2 variables.\n")
def Input():
global Arithmetic_Operator
print("0: Exit\n1: Addition\n2: Subtraction\n3: Multiplication\n4: Division\n5: Square root\n")
print("Only numbers 0 to 5 are accepted.")
Arithmetic_Operator = input("Which arithmetic operator do you want to use? ")
if Arithmetic_Operator == "0":
print("Exiting...")
exit()
elif Arithmetic_Operator == "1":
global Arithmetic_Operator_Addition
print("\n")
Arithmetic_Operator_Addition = "Addition"
Options()
elif Arithmetic_Operator == "2":
global Arithmetic_Operator_Subtraction
print("\n")
Arithmetic_Operator_Subtraction = "Subtraction"
Options()
elif Arithmetic_Operator == "3":
global Arithmetic_Operator_Multiplication
print("\n")
Arithmetic_Operator_Multiplication = "Multiplication"
Options()
elif Arithmetic_Operator == "4":
global Arithmetic_Operator_Division
print("\n")
Arithmetic_Operator_Division = "Division"
Options()
elif Arithmetic_Operator == "5":
global Arithmetic_Operator_Square_root
print("\n")
Arithmetic_Operator_Square_root = "Square root"
Options()
else:
print("Invalid input. Please try again.\n")
Input()
def Options():
if Arithmetic_Operator == "1":
print("Operator chosen: " + Arithmetic_Operator_Addition)
First_Number = float(input("First number: "))
Second_Number = float(input("Second number: "))
Answer = str(First_Number + Second_Number)
print("Answer: " + Answer + "\n")
Input()
elif Arithmetic_Operator == "2":
print("Operator chosen: " + Arithmetic_Operator_Subtraction)
First_Number = float(input("First number: "))
Second_Number = float(input("Second number: "))
Answer = str(First_Number - Second_Number)
print("Answer: " + Answer + "\n")
Input()
elif Arithmetic_Operator == "3":
print("Operator chosen: " + Arithmetic_Operator_Multiplication)
First_Number = float(input("First number: "))
Second_Number = float(input("Second number: "))
Answer = str(First_Number * Second_Number)
print("Answer: " + Answer + "\n")
Input()
elif Arithmetic_Operator == "4":
print("Operator chosen: " + Arithmetic_Operator_Division)
First_Number = float(input("First number: "))
Second_Number = float(input("Second number: "))
Answer = str(First_Number / Second_Number)
print("Answer: " + Answer + "\n")
Input()
elif Arithmetic_Operator == "5":
print("Operator chosen: " + Arithmetic_Operator_Square_root)
Number = float(input("Number: "))
Answer = sqrt(Number)
print("Answer: " + str(Answer) + "\n")
Input()
Input()
In the Input() module, all my input fields are designed in a way that only numbers 0 to 5 are accepted and other inputs are rejected. This way, I can prevent abuse of the input fields in the Input() module. However, in the Options() module, the input fields are susceptible to abuse if the user entered an alphabet or other symbols, due to the use of the float() function? Is there a way to prevent the script from crashing when such alphabets and symbols are entered in the Options() module?