I'm a beginner in coding and theres something wrong with my elif statement and i cant figure out what
For some reason this code gets stuck in the or, it will never execute the '4' option. We're trying to use less repetitive code, but nothing too advanced because we just starting learning python.
# defines menu
menu = '1- Sum of integers\n2- Sum of squares\n3- sum of cubes\n4- Geometric series'
# asks user for menu choice
print(menu)
menuChoice = 0
while menuChoice >= 0:
menuChoice = int(input(
'Please enter a choice from our menu. (enter a negative number to quit)\n'))
sum = 0
calcSum = 0
if menuChoice == 0:
print(menu)
elif menuChoice == 1 or 2 or 3:
n = int(input('Enter n: '))
for i in range(n + 1):
if menuChoice == 1:
sum += i
calcSum = n * (n + 1)/2
elif menuChoice == 2:
sum += i ** 2
calcSum = n * (n + 1) * (2 * n + 1)/6
elif menuChoice == 3:
sum += i ** 3
calcSum = (n + (n + 1) / 2) ** 2
elif menuChoice == 4:
x = int(input("Please Enter the Common Ratio: "))
n = int(input("Please Enter the Total Numbers in this Geometric Series: "))
for i in range(n + 1):
sum += x ** i