(Jun-17-2019, 12:46 PM)scotty501 Wrote: What if you wanted to force the input to be a number, and the same again, if not, error message and start again?https://python-forum.io/Thread-Validating-User-Input
(Jun-17-2019, 12:46 PM)scotty501 Wrote: Lastly, can you make the response ignore the capitalisation - so "Multiply" or "multiply" is acceptable?str.lower() will change your string to all lowercase. Then you only have to compare the lowercase .
(Jun-17-2019, 12:46 PM)scotty501 Wrote: how would you make itI would use dictionaries, not a massive if/elif condition
number1 = int(input("What is the first number?")) operator = input("What do you want to do + Plus - Minus * Multiply / Divide or p Power of? ") number2 = int(input("What is the second number?")) calculate = { '+':number1 + number2, '-':number1 - number2, } print(calculate[operator])
Recommended Tutorials: