I'm trying to create a calculator with the following code:
number_1 = " "
while number_1 not in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
number_1 = raw_input("Please enter your first number:")
if number_1 not in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
print "ERROR: Please type a valid number:"
print number_1
operator_symbol = " "
while operator_symbol not in ["+", "-", "*", "/"]:
operator_symbol = raw_input("Please enter an appropriate operator symbol:")
if operator_symbol not in ["+", "-", "*", "/"]:
print "ERROR: Please type one of the following operator symbols: +, -, *, /."
print operator_symbol
number_2 = " "
while number_2 not in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
number_2 = raw_input("Please enter your second number:")
if number_2 not in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
print "ERROR: Please type a valid number"
print number_2
They are spaced out while I work on them. For number_1
and number_2
I have defined the characters that I want to be used ('0'
-'9'
), yet when I use a number larger than 9
, it gives an error.
I want to use '0'
-'9'
as characters available, not the specific numbers.