-2
def main():
    while True:
        operation = raw_input('Choose an operation: ')

        if operation == 1:
            number_1 = int(raw_input("What is the first number you want to subtract? "))
            number_2 = int(raw_input("What do you want to subtract from it? "))
            sum = number_1 - number_2
            print('The answer is...')
            print(sum)
            break

        if operation == 2:
            number_1 = int(raw_input("What is the first number you want to subtract? "))
            number_2 = int(raw_input("What do you want to subtract from it? "))
            sum = number_1 - number_2
            print('The answer is...')
            print(sum)
            break

        if operation == 3:
            number_1 = int(raw_input("What is the first number you want to subtract? "))
            number_2 = int(raw_input("What do you want to subtract from it? "))
            sum = number_1 - number_2
            print('The answer is...')
            print(sum)
            break

        if operation == 4:
            number_1 = int(raw_input("What is the first number you want to subtract? "))
            number_2 = int(raw_input("What do you want to subtract from it? "))
            sum = number_1 - number_2
            print('The answer is...')
            print(sum)
            break

        else:
            print('Invalid operation')
            break
main()

When I try to input a number it doesn't recognise it and prints Invalid operation

Fabricator
  • 12,722
  • 2
  • 27
  • 40

4 Answers4

2

You have to convert the input to an integer with int():

operation = int(raw_input('Choose an operation: '))
pp_
  • 3,435
  • 4
  • 19
  • 27
0

set your if statements to something like:

if int(operation) == 1

or

if operation == str(1)
Simon
  • 9,762
  • 15
  • 62
  • 119
0

You have to compare strings:

if operation == "1":

gollum
  • 2,472
  • 1
  • 18
  • 21
0

operation needs to be an int if you have it checking against a int for your if statements.

operation = raw_input('Choose an operation: ')

should be

operation = int(raw_input('Choose an operation: '))

As a side note, make sure you proofread your code before asking. :)