see this is my code
print("""1. ADD
2. SUBTRACT
3. MULTIPLY
4. DIVIDE
5. SQUARE
6. SQUARE ROOT
7. CUBE
8. CUBE ROOT
9. POWER OF A NUMBER
10. FACTORIAL
11. TRIANGLE'S PERIMETER
12. TRIANGLE'S AREA
13. QUADRILATERAL'S PERIMETER
14. PARALLELOGRAM'S AREA
15. RHOMBUS'S AREA
17. RECTANGLE'S AREA
18. SQUARE'S AREA
19. TRAPEZIUM'S AREA
20. CIRCLE'S CIRCUMFERENCE
21. CIRCLE'S AREA
22. QUADRATIC EQUATION
23. SIMPLE INTEREST
24. COMPOUND INTEREST""")
while True:
user = str(input("Enter GO to continue or Q to exit: "))
if user == 'GO':
user_input = str(input("Enter here the serial number or the name in capital for what you want to calculate: "))
if user_input == 'ADD' or 1 :
add()
elif user_input == 'SUBTRACT' or 2 :
sub()
elif user_input == 'MULTIPLY' or 3 :
mlt()
elif user_input == 'DIVIDE' or 4 :
div()
elif user_input == 'SQUARE' or 5 :
sqr()
elif user_input == 'SQUARE ROOT' or 6 :
sqrt()
elif user_input == 'CUBE' or 7 :
cube()
elif user_input == 'CUBE ROOT' or 8 :
cube_root()
elif user_input == 'POWER OF A NUMBER' or 9 :
power()
elif user_input == "TRIANGLE'S PERIMETER" or 11 :
triangle_perimeter()
elif user_input == "QUADRILATERAL'S PERIMETER" or 13 :
quadrilateral_perimeter()
elif user_input == "PARALLELOGRAM'S AREA" or 14 :
parallelogram_area()
elif user_input == 'FACTORIAL' or 10 :
factorial()
elif user_input == "RHOMBUS'S AREA" or 15 :
rhombus_area()
elif user_input == "RECTANGLE'S AREA" or 17 :
rectangle_area()
elif user_input == "SQUARE'S AREA" or 18 :
square_area()
elif user_input == "CIRCLE'S AREA" or 21 :
circle_area()
elif user_input == "CIRCLE'S CIRCUMFERENCE" or 20 :
circle_circumference()
elif user_input == "QUADRATIC EQUATION" or 22 :
qaudratic_solver()
elif user_input == "SIMPLE INTEREST" or 23 :
simple_interest()
elif user_input == "COMPOUND INTEREST" or 24 :
compound_interest()
elif user_input == "TRIANGLE'S AREA" or 12 :
triangle_area()
elif user_input == "TRAPEZIUM'S AREA" or 19 :
trapezium_area()
else:
print("Invalid input!!")
elif user == 'Q':
break
else:
print("Invalid input!!")
and when I run it when I put any number or name in the input line instead of calling out the function with respect to the number or name it calls out to the add() function which relates number 1 and and name "ADD" Why is this happening? Please help me... PS: I had done this in google colab so the actual functions are written in a separate "cell" if you know google colab you'll know :) but anyways here are functions too
import cmath
import functools
def add():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the first number: "))
val2 = float(input("Enter the second number: "))
print("The result is: ", val1 + val2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def sub():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the first number: "))
val2 = float(input("Enter the second number: "))
print("The result is: ", val1 - val2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def mlt():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the first number: "))
val2 = float(input("Enter the second number: "))
print("The result is: ", val1*val2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def div():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the first number: "))
val2 = float(input("Enter the second number: "))
print("The result is: ", val1/val2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def sqrt():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the number: "))
print("The result is: ", cmath.sqrt(val1))
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def sqr():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the number: "))
print("The result is: ", val1**2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def power():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the number: "))
val2 = float(input("Enter the power of the number: "))
print("The result is: ", val1**val2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def square_area():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the value of the side: "))
print("The area of the square is: ", val1**2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def rectangle_area():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the value of the length: "))
val2 = float(input("Enter the value of the breadth: "))
print("The area of the square is: ", val1*val2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def circle_circumference():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the radius of the circle: "))
print("The circumference of the circle is: ", (val1*44)/7)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def circle_area():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the radius of the circle: "))
print("The area of the circle is: ", (val1*val1*22)/7)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def rhombus_area():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the value of first diagonal: "))
val2 = float(input("Enter the value of the second diagonal: "))
print("The area of the rhombus is: ", 0.5*val1*val2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def parallelogram_area():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the value of height: "))
val2 = float(input("Enter the value of the correspondent base: "))
print("The area of the parallelogram is: ", 0.5*val1*val2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def quadrilateral_perimeter():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
a = float(input("Enter the first side of the quadrilateral: "))
b = float(input("Enter the second side of the quadrilateral: "))
c = float(input("Enter the third side of the quadrilateral: "))
d = float(input("Enter the foruth side of the quadrilateral: "))
if ((a + b + c> d) and (a + b + d> c) and (b + c + d> a) and (a + d + c> b)) :
print("The perimeter of the qaudrilateral is : ", a+b+c+d)
else :
print("Quadrilateral is not valid.")
elif user_input == 'Q':
break
else:
print("invalid input")
def trapezium_area():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
par1 = float(input("Enter the value of the first parallel side: "))
par2 = float(input("Enter the value of the second parallel side: "))
hei1 = float(input("Enter the the value of the height: "))
print("The area of the trapezium is: ", 0.5*hei1*(par1+par2))
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def triangle_perimeter():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
a = float(input("Enter the first side of the triangle: "))
b = float(input("Enter the second side of the triangle: "))
c = float(input("Enter the third side of the triangle: "))
if ((a + b > c) and (a + c > b) and (b + c > a)) :
print("The perimeter of the traingle is: ", a+b+c)
else :
print("Triangle is not valid.")
elif user_input == 'Q':
break
else:
print("invalid input")
def triangle_area():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
area_method = str(input("Enter Heron or Traditional(0.5*height*base): "))
if area_method == 'Heron':
a = float(input("Enter the first side of the triangle: "))
b = float(input("Enter the second side of the triangle: "))
c = float(input("Enter the third side of the triangle: "))
if ((a + b > c) and (a + c > b) and (b + c > a)) :
s = (a+b+c)*0.5
print("The area of the triangle is ", cmath.sqrt((s-a)*(s-b)*(s-c)*(s)))
else:
print("Triangle is not valid!!")
elif user_input == 'Traditional':
a = float(input("Enter the value of the height: "))
b = float(input("Enter the value of the correspondent base: "))
print("The area of the triangle is ", 0.5*a*b)
else:
print("Invalid input!!")
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def qaudratic_solver():
while True:
user_input = str(input("Enter the GO to continue or Q to exit: "))
if user_input == 'GO':
a = float(input("Enter the coeffiecient of x^2: "))
b = float(input("Enter the coeffiecient of x: "))
c = float(input("Enter the constant: "))
D = cmath.sqrt(b*b - 4*a*c)
F = 2*a
X1 = (-b + D)/(F)
X2 = (-b - D)/(F)
print("The values of x are: ", X1, ", ", X2)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def cube():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the number: "))
print("The result is: ", val1**3)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def cube_root():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
val1 = float(input("Enter the number: "))
print("The result is: ", val**1/3)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def compound_interest():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
P = float(input("Enter the principal amount: "))
IR = float(input("Enter the interest rate: "))
T = float(input("Enter the time period: "))
N = float(input("Enter the number of times interest is compunded per unit time 't': "))
A = P*((1+((IR/100)/N))**(N*T))
CI = A-P
print("The final amount will be ", A, " and the compund interest will total up to ", CI)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def simple_interest():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
P = float(input("Enter the principal amount: "))
R = float(input("Enter the interest rate: "))
T = float(input("Enter the time period: "))
SI = (P*R*T)/100
A = P + SI
print("The final amount will be ", A, " and the simple interest will total up to ", SI)
elif user_input == 'Q':
break
else:
print("Invalid input!!")
def factorial():
while True:
user_input = str(input("Enter GO to continue or Q to exit: "))
if user_input == 'GO':
a = int(input("Enter the number: "))
print(functools.reduce(lambda x,y : x * y, range(1,a+1)))
elif user_input == 'Q':
break
else:
print("Invalid input!!")