0

I'm trying to make a program and would like to implement a function that allows the user to quit whenever they enter "quit". My issue is that I want to get two inputs (also integers) at once so it looks like this:

try:
    a, b = input("Enter two numbers: ").split()
except:
    print("Enter two NUMBERS please! ")
try:
    a = int(a)
    b = int(b)
except:
    print("Enter two NUMBERS please! ")

The try/except is mainly so if they enter words instead of numbers, it'll prompt them again for valid numbers. I would like to make it so that if the user enters "quit", then the program ends or runs another print function rather than giving a ValueError since it expects two values. I'm not sure how to accept only one specific value.

Thanks!

codelie
  • 1
  • 2
  • 2
    Bare `except` clauses are just asking for trouble. https://stackoverflow.com/q/54948548/843953 – Pranav Hosangadi Oct 24 '22 at 21:39
  • Welcome to Stack Overflow! Check out [ask]. Where's the `.split()`? Where's the conversion to `int()`? I get what you're asking, and the link I'm recommending should be useful, but your current code is incomplete. See [How to split a string of space separated numbers into integers?](/q/6429638/4518341) – wjandrea Oct 25 '22 at 02:14
  • Related: [Asking the user for input until they give a valid response](/q/23294658/4518341) – wjandrea Oct 25 '22 at 02:15

0 Answers0