[Python] I keep getting an invalid syntax and, I don't know why I am getting it [closed]

Discussão em 'Python' iniciado por Stack, Maio 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have been working on this problem for a long time and trying to get it to work. It is the line that is pointed at.

    print("Only enter the numbers between 1-8.")
    print("Select an operation:")
    print("1. Add")
    print("2. Subtract")
    print("3. Multiply")
    print("4. Divide")
    print("5. Detect prime numbers")
    print("6. Generate prime factors")
    print("7. Simplify square roots")
    print("8. Solve for a variable")

    choice = input("Enter your choice (1-8): ")

    if choice in ('1', '2', '3', '4', '5', '6', '7', '8'):
    if choice == '1':
    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))
    print(num1, "+", num2, "=", num1 + num2)

    elif choice == '2':
    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))
    print(num1, "-", num2, "=", num1 - num2)

    elif choice == '3':
    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))
    print(num1, "*", num2, "=", num1 * num2)

    elif choice == '4':
    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))
    if num2 == 0:
    print("Cannot divide by zero")
    else:
    print(num1, "/", num2, "=", num1 / num2)

    elif choice == '5':
    num = int(input("Enter a number: "))
    print(f"You entered: {num}")
    if num <= 1:
    print(num, "is not a prime number")
    elif num <= 3:
    print(num, "is a prime number")
    elif num % 2 == 0 or num % 3 == 0:
    print(num, "is not a prime number")
    else:
    i = 5
    while i * i <= num:
    if num % i == 0 or num % (i + 2) == 0:
    print(num, "is not a prime number")
    break # Important: Break out of the loop if a divisor is found
    i += 6
    else:
    print(num, "is a prime number")

    > elif choice == '6':

    def prime_factors(n):
    factors = []
    d = 2
    while d * d <= n:
    while n % d == 0:
    factors.append(d)
    n //= d
    d += 1
    if n > 1:
    factors.append(n)
    return factors
    num = int(input("Enter an integer greater than 1: "))
    if num <= 1:
    print("Please enter an integer greater than 1.")
    else:
    print("Prime factors:", prime_factors(num))

    elif choice == '7':
    print("This option is not yet implemented.")

    elif choice == '8':
    print("This option is not yet implemented.")

    else:
    print("Invalid input")


    I also have other errors in it as well, but this one I need the most help on because I don't know what to do at all. The one that has an arrow is the line I need help on.

    Continue reading...

Compartilhe esta Página