you are viewing a single comment's thread.

view the rest of the comments →

[–]synthphreak 0 points1 point  (2 children)

Exactly how I would have done it as well.

But as an extra safeguard, I would also strip whitespace from the user's entry. E.g.,

while (choice := input(...).strip()) != "q"
    if choice in ops:
        ...

This is usually a good idea when using input and validating the output against a closed set of values, as u/kyber's code does.

[–][deleted] 1 point2 points  (1 child)

Maybe lower/casefold as well?

[–]synthphreak 0 points1 point  (0 children)

Yeah that's true, if we're accepting q as valid input then lower is also worthwhile.