-1

I need to have it continue to ask for input until q or quit is entered:

shape = input("Press enter to start session").lower()
a = 0
b = 0
h = 0
r1 = 0
r2 = 0
r3 = 0
while shape != "q" or shape != "quit":
    shape = input("Enter shape type Cube or Pyramid or Ellipsoid (q to quit)").lower()
    if shape == "c" or shape == "cube":
        a = input("Side length: ")

    elif shape == "p" or shape == "pyramid":
        b = input("Base length: ")
        h = input("Height: ")

    elif shape == "e" or shape == "ellipsoid":
        r1 = input("Radius 1: ")
        r2 = input("Radius 2: ")
        r3 = input("Radius 3: ")

    elif shape != "q" or shape != "quit":
        shape = input("Enter shape type Cube or Pyramid or Ellipsoid (q to quit)").lower()

    if shape == "q" or shape == "quit":
         print("Your session has ended")

I enter q or quit put it still asks for another shape and it continues to ask for the shape endlessly.

Shaya Ulman
  • 1,299
  • 1
  • 12
  • 24
  • 1
    `while shape != "q" or shape != "quit"` will always evaluate to `True`. All strings are not equal to at least one of `"q"` or `"quit"`. Change that `or` to an `and`. – mypetlion Oct 16 '19 at 18:53

2 Answers2

1

while shape != "q" or shape != "quit": is causing issues. If your string is q, it's not equal to quit, so the loop will keep running - and vice versa. Use this instead:

while shape != "q" and shape != "quit":

Now, if either of these conditions fail, the while loop will break.

Nick Reed
  • 4,989
  • 4
  • 17
  • 37
0

I suggest you try using break:

while True:
    ...
    if shape == "q" or shape == "quit":
        print("Your session has ended")
        break

Does that work?

Ralf
  • 16,086
  • 4
  • 44
  • 68