Python Forum
Syntax Error: Invalid Syntax in a while loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax Error: Invalid Syntax in a while loop
#1
I'm fairly new to this stuff and keep getting an error message on line 19:

(while user_input.lower() != "quit":
^
SyntaxError: invalid syntax

let me know if you see the problem! :)
# import math library
import math
# import volume.py to import the volume calculations
import volume
# define main function in order to store the given variables
def main():
    cube_vol = 0
    pyramid_vol = 0
    ellip_vol = 0
    cube_result = []
    pyramid_result = []
    ellipsoid_result = []
    option = ""
    user_input = (input("Choose a shape: cube, pyramid, or ellipsoid or q/quit to quit")

    while user_input.lower() != "quit":
    # if the user inputs "cube", the following path is executed to prompt the user with instructions to determine the volume
        if user_input.lower() == "cube":
            # program will ask user to enter the cube's width
            cube_width = input("Enter cube width:")
             # if the input is valid, the program will calculate the volume of the cube
            if isDigit(cube_width) == True:
            cube_vol = cube_volume(float(cube_width))
            #use imported values from volume file to determine the volume of the specific cube value
            volume.cube_volume(cube_vol)
            print("The volume of the cube with the length of {} is {}.".format(width, cube_vol))
            # if the output was invalid (not a valid number) then the program will display the input is invalid
            else:
            option = "cube"
            print("Invalid input. Please try again.")
Reply
#2
Please use Python tags for formatting code in your posts.
That said, in the line before that you have mismatched parentheses - 2 open and only 1 close.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,320 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  Invalid syntax Slome 2 1,970 May-13-2022, 08:31 PM
Last Post: Slome
  How to write a recursion syntax for Sierpinski triangle using numpy? Bolzano 2 3,872 Apr-03-2021, 06:11 AM
Last Post: SheeppOSU
  urgent I got a syntax errors alm 2 5,869 Feb-28-2021, 02:54 PM
Last Post: alm
  print(f"{person}:") SyntaxError: invalid syntax when running it AryaIC 11 16,355 Nov-07-2020, 10:17 AM
Last Post: snippsat
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 2,005 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 2,008 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 1,974 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  Invalid syntax error, where? tucktuck9 2 3,424 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Python for syntax conversion kingsman 23 9,523 Apr-27-2020, 03:24 PM
Last Post: kingsman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020