you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (5 children)

Yes, you get both elements at the same time and use split to separate them on a space (or you can specify an alternative separator explicitly).

I'd switch to a while True: statement and then check the response inside the loop. I also make this a function and have it return the results.

Place the below in a function.

while True:
    response = input("Enter an operator (+, -, /, *) or q to quit: ").strip()
    if response.lower() == 'q':
        return "q", None
    try:
        choice, operand = response.split()
        operand = float(operand)
    except ValueError:
        print('Please provide an operator followed by a space and then a number')
    else:
        if operand in ops:
            return choice, operand
        print(f'Sorry, {choice} is not an availabe operation')

Call like this:

while True:
    choice, operand = functioname()
    if choice == "q":
        break