I am currently creating a calculator that asks the user a series of questions to calculate the answer to their sum, however I have quickly come across the fact that I am using multiple if statements, and it has made my code extremely difficult and tiring to read.
I would like to know if there is an alternative method to using multiple if statements that each have a different function that takes up less space and completes the same task.
Here's a sample of my code:
def decision():
choice = input("""
Please Select an Option:
Type 1 for Addition, Subtraction, Multiplication and Division.
Type 2 for Squares or Square Roots, Cubes or Cube Roots, Powers, Roots and Percentages.
Type 3 for Greater Than and Less Than.
Type 4 for H.C.F(Highest Common Factor), G.C.D(Greatest Common Divisor) and L.C.M(Least Common Multiple).
Type 5 for Converting Degrees to Radians.
Type 6 for Calculating Grades from Marks.
Type 7 for Perimeter, Circumference, Area, Surface Area and Volume of Shapes.
Selection: """)
if choice == '1':
ASMD()
elif choice == '2':
SCERP()
elif choice == '3':
GL()
elif choice == '4':
HCF_GCD_LCM()
elif choice == '5':
DR()
elif choice == '6':
CG()
elif choice == '7':
PCASAV()
else:
print("You have not selected a Valid Option. Please run the program again.")
input("Press Enter to continue...")
exit()
Thanks in advance!