Thanks for all the great responses, I am trying to adapt my sample code as I want to learn what is happening, rather than just copy someone else code. I am playing with the first suggestion and using the sample code below.
Q1 - Would that be because (int input) will not work with text.isdigit, so the only way I can get the two to play nice is to make it a input not int input, which then of means, my if and elif statement does not work as it does not see it as an integer?
Q2 - How would you fix it?
As I say, I am trying to avoid just copying peoples code, and understand each part first. (Very early days).
My revised code, which does not output integer as below:
while True: text = input('Please enter an integer: ') if text.isdigit(): number = int(text) break print('{} is not an integer.'.format(text)) print((number + 1) * 2)This breaks my original code as I would expect.
Q1 - Would that be because (int input) will not work with text.isdigit, so the only way I can get the two to play nice is to make it a input not int input, which then of means, my if and elif statement does not work as it does not see it as an integer?
Q2 - How would you fix it?
As I say, I am trying to avoid just copying peoples code, and understand each part first. (Very early days).
My revised code, which does not output integer as below:
while True: number1 = input('Please enter the first number: ') if number1.isdigit(): number = int(number1) break print('{} is not a number! Try again.'.format(number1)) operator = input("What do you want to do + Plus - Minus * Multiply / Divide or p Power of? ") while True: number2 = input('Please enter the second number: ') if number2.isdigit(): number = int(number2) break print('{} is not a number! Try again.'.format(number2)) if operator == "+": answer = number1+number2 elif operator == "-": answer = number1-number2 elif operator == "*": answer = number1*number2 elif operator == "/": answer = number1/number2 if operator == "Plus": answer = number1+number2 elif operator == "Minus": answer = number1-number2 elif operator == "Multiply": answer = number1*number2 elif operator == "Divide": answer = number1/number2 elif operator == "p": answer = number1**number2 elif operator == "power of": answer = number1**number2 print("The answer is " + str(answer))