Ask coding questions

← Back to all posts
How to fix
GDDuck15 (22)

I am Trying to make a calculator in my project but I can't fix it I need help!

Answered by Coder100 (18057) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18057)

yeah, you haven't really added any code to do the calculations yet, here's an example:

eq = input('+ - * / ')
n1 = float(input("Enter first number: "))
n2 = float(input("Enter second number: "))


if eq == '+':
  print(n1 + n2)
elif eq == '-':
  print(n1 - n2)
elif eq == '*':
  print(n1 * n2)
elif eq == '/':
  print(n1 / n2)
InvisibleOne (2931)

print(eval(input())) is the lazy way, or you can do something like this

firstNum = input("First Number: ")
secondNum = input("Second Number: ")
symbol = input("(+ or -): "
if symbol == '+':
  print(firstNum  + secondNum)
elif symbol == '-'
  print(firstNum - secondNUm)
IMayBeMe (455)

Try to use if statements like this:

if eq == “+”:
  print(str(n1 + n2))

You can than repeat this with all the operations and just switch the sign