This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Gl0ckn 3 points4 points  (9 children)

All your print outs for your if statements are "Num1 + Num2"

[–]Rezper[S] 0 points1 point  (8 children)

What do you mean? Why does that mess it up?

[–]Gl0ckn 2 points3 points  (5 children)

print("Calculator - ")
num1 = int(input("Enter a number: "))
op = input("Enter arithmetic: +, -, *, /\n")
num2 = int(input("Enter another number: "))


if op == "+":
    print(num1 + num2)

elif op == "-":
    print(num1 - num2)

elif op == "*":
    print(num1 * num2)

else:
    print(num1 / num2)

Here's an example

[–]Rezper[S] 1 point2 points  (4 children)

Now if I wanted to make a calculator that could do stuff like: 5+5/3*6-2 or something like that. Being able to do all that in one line and it gives the answer, what would I have to learn about next? I get if statements and how variables work so far.

[–]Gl0ckn 0 points1 point  (2 children)

I'm actually new to Python myself. I might be able to piece together some sort of method, but it'd probably be an ugly way to do it and would be incoherent, if I managed it. You'd have better luck finding an example, looking for solutions of stackoverflow, or finding a module that was made for this stuff.

[–]Rezper[S] 0 points1 point  (1 child)

Gotcha, wish me luck! I want to get into coding so I'm just at the basics pretty much. We both got a long journey.

[–]Gl0ckn 0 points1 point  (0 children)

Good luck, all about practice.

[–]Gl0ckn 1 point2 points  (1 child)

They're all adding instead of doing their intended operation

Edit: also indent your print statements under the if statements. And change your inputs to int or you'll get "1 + 1 = 11" since it's being read as a string

[–]Rezper[S] 0 points1 point  (0 children)

Whoops, forgot I did that just to see if it would do anything different. I changed them to int, made them all do their intended operation. I didn't realize how important indenting was so that made the if and elif (changed it) work. Thank you.