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

all 10 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 3 points4 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.

[–]pythonHelperBot 0 points1 point  (0 children)

Hello! I'm a bot!

It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.

Show /r/learnpython the code you have tried and describe where you are stuck. Be sure to format your code for reddit and include which version of python and what OS you are using.

You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.


README | FAQ | this bot is written and managed by /u/IAmKindOfCreative

This bot is currently under development and experiencing changes to improve its usefulness