# Search the Community

Showing results for tags 'calculator'.

• ### Search By Tags

Type tags separated by commas.

### Forums

• General
• General
• Blog
• One Stop Programming Tutorials
• Python Beginner Series
• Programming Languages
• Python
• C++
• C#
• Arduino
• Other Languages

• 0 Replies

• 0 Views

Found 7 results

1. ## My Code Is Not Working

Hey guys, I have been watching kjdelectronics on his python tutorial videos and have recently gotten to the part where you build a calculator, but I'm having trouble in the finalization process of it all. My code seems to be flawed - I keep getting a syntax error and have no idea why because I have copied the code exactly as he presents it in the video. I was wondering if anyone could look at it and tell me where my issue (bug) is located. Here is my code and a screenshot of the syntax error. #Returns the sum of num1 and num2 def add(num1, num2): return num1 + num2 #Returs the result of subtracting num1 - num2 def sub(num1, num2): return num1 - num2 #Returns the result of multiplying num1 * num2 def mul(num1, num2): return num1 * num2 #Returns the result of dividing num1 / num2 def div(num, num2): return num1 / num2 def main(): operation = input("What do you want to do? (+, -, *, /): ") if(operation != '+' and operation != '-' and operation != '*' and operation != '/'): #invalid operation print("You must enter a valid operation") else: var1 = int(input("Enter num1: ") var2 = int(input("Enter num2: ") if(operation == '+'): print(add(var1, var2)) elif(operation == '/'): print(div(var1, var2)) elif(operation == '-'): print(sub(var1, var2)) else: print(mul(var1, var2)) main()

3. ## calculator Statement seems to have no effect

I was making a calculator that takes BEDMAS (Proper order of operations) into account. I'm very new (I just started today) but I managed to find a simple code for an ordinary calculator (like the ones that you find in phones, computers, etc) that works in a command line, and basing my code off of that. The problem is that I am trying to display the 'operationanswer2' of what I can assume is an integer or a variable (idk man, I'm not very good at this) but it keeps giving me a error message saying 'This inspection detects statements without any effect' He is the code. Due to fear of plagiarism I will only give you 3 parts of it that gives you how it's defined, and what I'm using to print it. operationanswer1 = (number_1 + number_2) if operation2 == '+' and operation1 == '+': operationanswer2 = (operationanswer1 + number_3) print!=operationanswer2 This is not the full code I am just afraid of plagiarism. Also I have school tomorrow so I will only be able to get back to you next evening.
4. ## Calculator debug

I've run into an issue with the calculation function (python 3.3) where addition works but sub, mul and div each return: Traceback (most recent call last): File "./calc.py", line 22, in <module> main() File "./calc.py", line 15, in main print(subtract(var1, var2)) NameError: global name 'sub' is not defined I have also tried the entire word 'subtract' but no diff. Here is the relevant code snippet: else: var1 = int(input("Enter first value:")) var2 = int(input("Enter second value:")) if(operation == '+'): print(add(var1, var2)) elif(operation == '-'): print(sub(var1, var2)) elif(operation == '*'): print(mul(var1, var2)) else: print(div(var1, var2))
5. ## A second of your time to solve a simple problem?

Greetings! I'm brand new to Python, and I've been following the One Stop Programming YouTube tutorial to learn how to use it. Unfortunately, I've come across a problem that I absolutely cannot comprehend as a new programmer, and I was looking for assistance. I'm sure the problem is only minor and will be immediately obvious to anyone with more than a few hours experience. If you look at my attachment you will see a simple calculator, made with the mentoring of the online tutorial. (https://youtu.be/Ow3CcOGNIss?t=1247) I have followed the tutorial, almost to the letter, but my variables are different, and so are some of my prints, but those don't matter as far as I know. The problem is with Y. Highlighted red. It is an unrecognised syntax and I have no idea why, as the tutorial shows exactly the same thing, but with valid syntax. Can anyone shed any light on this situation? Thanks a bunch in advance!