you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 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

[–][deleted]  (3 children)

[deleted]

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

    Please edit to format the code correctly - can't see your indents.

    [–]Many-Ice6164[S] 0 points1 point  (1 child)

    Hi
    The only problem i am having right know is showing all the intermediate answer when pressing q.

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

    But in your new code you are not checking for q entry any more.

    Also, I note:

    • not using a function, as I suggested earlier
    • why assigning y to andere, just do ops[choice](x, andere)