0

I'm currently learning python and I have to make a calculator which has some scientific operations. Right now I am making a code that detects if it an operation listed or not.

import math

op=input("Type in Operation Here(*,/,-,+, sine, cosine,tangent,**,sqrt,pi)")
if op!= '*',"/",'-','+','sine','cosine','tangent','**','sqrt','pi':
    print("Please type in a Operator that is listed above")
elif op== "sine":
    sine=float(input("Enter Number for Sine"))
    print(math.sin(sine))
elif op== "cosine":
    cos=float(input("Enter Number for Cosine"))
    print(math.cos(cos))
elif op== "tangent":
    tang=float(input("Enter Number for Tang"))
    print(math.tan(tang))
elif op=="sqrt":
    sqrt=float(input("Enter Number For Square Root:"))
    print(math.sqrt(sqrt))
elif op=="pi":
    pi=float(input("Enter Number to Pi:"))
    print(math.pi*pi)
else:
    nub=float(input("Enter Number Here:"))
    nub2=float(input("Enter Another Number Here:"))
    if op == '+':
        print(nub+nub2)
    elif op == '-':
        print(nub-nub2)
    elif op == '*':
        print(nub*nub2)
    elif op == '/':
        print(nub/nub2)
    else:
        if op =="**":
            exp = float(input("Enter Base Here:"))
            power = float(input("Enter Power Here:"))
            print(exp**power)

When I run the code it has an invalid syntax pointing at line three. Is there a simple way to fix this error?

Wes Hardaker
  • 21,735
  • 2
  • 38
  • 69
  • 6
    It seems it should be `if op not in ['*',"/",'-','+','sine','cosine','tangent','**','sqrt','pi']:` https://stackoverflow.com/questions/10406130/check-if-something-is-not-in-a-list-in-python – Brian Destura Jun 02 '21 at 01:57
  • It raises an exception if `nub2` is 0 at `elif op == '/': print(nub/nub2)` – Klim Bim Jun 02 '21 at 06:49
  • Hi welcome to the stackoverflow community. Could you rephrase your question? Imagine your question being helpful for other people to find a solution to a similar problem. Another suggestion is to have a look what IDE's like pycharm or vscode can bring you. – studioj Jun 03 '21 at 07:03

1 Answers1

2
if op not in ['*',"/",'-','+','sine','cosine','tangent','**','sqrt','pi']:
Amir Saadallah
  • 668
  • 1
  • 8
  • 19