quit2 = True
while quit2 == True:
    delete = input('\nIf you would like to delete a guest, enter their guest number. '
                   '\nIf you would  like to skip this step press Enter.')
if isinstance(delete, int):
    list[delete].remove()
else:
    break
            Asked
            
        
        
            Active
            
        
            Viewed 57 times
        
    -1
            
            
         
    
    
        Connor Johnson
        
- 1
- 2
- 
                    Possible duplicate of [Terminating a Python script](https://stackoverflow.com/questions/73663/terminating-a-python-script) – ababak Oct 02 '19 at 15:14
- 
                    1if you dont set new value to quit2 will never change... (list[delete].remove()) doesnt make sense for me – Wonka Oct 02 '19 at 15:16
- 
                    1What's the point of `quit2` if you aren't allowed to modify it? Just use `while True:` if you have an explicit `break` condition in the loop. – chepner Oct 02 '19 at 15:24
- 
                    2`delete` will never be an instance of `int`; `input` always returns a `str`. You probably want `delete = int(delete)`, with a `try` statement to catch any errors in the conversion attempt. – chepner Oct 02 '19 at 15:25
2 Answers
1
            
            
        Assuming that the if statement not being in the while loop is a formatting issue in the question, then the only problem with this code is that the if statement condition will never be true, since input() always returns a string, not an int.
Instead of using an if/else block, maybe try a try/except block:
while True:  # Don't need 'quit2', since it's never going to change
    delete = input('\nIf you would like to delete a guest, enter their guest number. '
                   '\nIf you would  like to skip this step press Enter.')
    try:
        delete = int(delete)
        list[delete].remove()
    except ValueError:  # if int(delete) fails because the string isn't numeric, exit loop
        break
    except IndexError:  # if list index out of range, let them try again
        print("That guest doesn't exist. Please try again.")
        continue
 
    
    
        Ahndwoo
        
- 1,025
- 4
- 16
0
            
            
        use break inside your while loop inside an if so the rest of your code will continue, but if you want to terminate it: import sys and use sys.exit()
 
    
    
        Martin Pavelka
        
- 49
- 1
- 2
- 7