-2

I'm very new to python and was wondering what is wrong with this code:

num1 = input("Please Eneter A Number")
num2 = input("Please Enter Another Number")

operation = input("Please Enter An Operation You Want To Do (example: +, -, *, /): ")

if operation == +:
    print(num1 + num2)

if operation == -:
    print(num1 - num2)

if operation == /:
    print(num1 / num2)

if operation == *:
    print(num1 * num2)

this is the error I get when trying to run this code:

    if operation == +:
                     ^
SyntaxError: invalid syntax

I could not find any problem of this sort on this forum. Please forgive me if this is a dumb question.

Michael Robellard
  • 2,268
  • 15
  • 25
  • 6
    you're missing your quotes, e.g. `'+'` – Chris_Rands Aug 27 '18 at 15:33
  • 1
    Also, `input()` returns strings, so num1 and num2 aren't integers, so your math operations won't work. To convert the input to integer form, use `num1 = int(input('enter a number'))` – John Gordon Aug 27 '18 at 15:37
  • 2
    In future, you should work out for yourself which part of the code is relevant to the bug. You can delete almost all of your code and still get the same bug. This process means you're not wasting other people's time and can help you fix it yourself. – Denziloe Aug 27 '18 at 15:40

2 Answers2

3

Python expects to receive strings as stdin input, so try

if operation == '+':

Also, your num1, num2 are also going to be strings, so you'll need to call

num1 = int(num1) 

or

num1 = float(num1) 

on them to make them integers or floats (and same with num2)

khelwood
  • 55,782
  • 14
  • 81
  • 108
0

Each of your operators must be in quotes as you are recieving a character input. Besides, you must convert your input numbers to int or float

Ravi S
  • 139
  • 3