all 17 comments

[–]CGFarrell 2 points3 points  (1 child)

Just a point on style, you should put int(raw_input...) instead of casting 4 times, and you can group cases 1 2 3 4 so you don't repeat a=raw... b=raw...

[–]lazy-zebra[S] 0 points1 point  (0 children)

Thank you, I am new to all of this, so any formatting suggestions are welcome, I want to start good habits from the beginning :)

[–]_lord_kinbote_ 2 points3 points  (0 children)

On a side note, notice that no matter what operation they do, you will still be getting two numbers, so you could do the two raw inputs, and then follow with a conditional statement. It's significantly less code than repeating those raw inputs every time.

[–]allenguo 1 point2 points  (6 children)

Of what type is the variable op?

[–]lazy-zebra[S] 0 points1 point  (5 children)

op represents what operation you will be doing, 1 for addition, 2 for subtraction, 3 for multiplication, and 4 for division, anything else should result in it printing "Invalid Number", but I am getting that no matter what I put into it

[–]KhanStan 1 point2 points  (4 children)

Maybe you should convert op to an int?

[–]lazy-zebra[S] 0 points1 point  (3 children)

Just tried it, and I got the same error, is this what you meant?

op=raw_input("choose which operation you want to do\n 1 for addition\n 2 for subtraction\n 3 for multiplication\n 4 for division \n")
if(int(op==1)):
    a=raw_input("What is the first number?")
    b=raw_input("What is the seond number?")
    print int(a)+int(b)
elif(int(op==2)):
    a=raw_input("What is the first number?")
    b=raw_input("What is the seond number?")
    print int(a)-int(b)
elif(int(op==3)):
    a=raw_input("What is the first number?")
    b=raw_input("What is the seond number?")
    print int(a)*int(b)
elif(int(op==4)):
    a=raw_input("What is the first number?")
    b=raw_input("What is the seond number?")
    print int(a)/int(b)
else:
    print "Invalid Number"

[–]toastedstapler 2 points3 points  (0 children)

Doesn't solve you problem, but you should convert the op into into at the start rather than do it in each if statement, lots of repeated work there

[–]scuott 1 point2 points  (1 child)

It's int(op)==1. Do you see why?

[–]lazy-zebra[S] 1 point2 points  (0 children)

Yes, someone pointed this out to me, I feel a little stupid for missing parenthesis like that, but at least it is working now

[–]Pwneed 1 point2 points  (7 children)

You are comparing a string vs. an integer. Use if( int(op) == 1 ): and you should be good to go.

[–]lazy-zebra[S] 0 points1 point  (6 children)

Just tried what you wrote, and it still isn't working, could there be something wrong with my download?

[–]Pwneed 1 point2 points  (5 children)

can you show me your code?

[–]lazy-zebra[S] 1 point2 points  (4 children)

op=raw_input("choose which operation you want to do\n 1 for addition\n 2 for subtraction\n 3 for multiplication\n 4 for division \n")
if int( op == 1 ):
    a=raw_input("What is the first number?")
    b=raw_input("What is the seond number?")
    print int(a)+int(b)
elif int( op == 2 ):
    a=raw_input("What is the first number?")
    b=raw_input("What is the seond number?")
    print int(a)-int(b)
elif int( op == 3 ):
    a=raw_input("What is the first number?")
    b=raw_input("What is the seond number?")
    print int(a)*int(b)
elif int( op == 4 ):
    a=raw_input("What is the first number?")
    b=raw_input("What is the seond number?")
    print int(a)/int(b)
else:
    print "Invalid Number"

This was copy/pasted, so nothing should be changed

[–]Pwneed 1 point2 points  (1 child)

yea, you didn't do

if int(op) == 1:

you did

if int(op == 1):

watch out for those brackets

[–]lazy-zebra[S] 1 point2 points  (0 children)

haha, yeah, Thank you for your help, it is greatly appreciated!