LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python Syntax Error (https://www.linuxquestions.org/questions/programming-9/python-syntax-error-4175662140/)

Gyroman 10-07-2019 07:00 AM

Python Syntax Error
 
Very simple Python question

This code comes at the beginning of a program before a while statement

Code:

A = int(input("A ="))
N = int(input("N ="))

PrN = (1/A)*(((N-N/A)/N)
imp = 1/PrN

when run produces
Code:

imp = 1/PrN
  ^ Syntax Error

Why is this a syntax error?

Ser Olmy 10-07-2019 07:26 AM

Mismatched number of parentheses:
Quote:

Originally Posted by Gyroman (Post 6044571)
Code:

PrN = (1/A)*(((N-N/A)/N)
imp = 1/PrN



teckk 10-07-2019 09:32 AM

Whole thing is a mess.

Code:

>>> A = 5
>>> N = 2
>>> PrN = ((1/(A))*((N)-((N)/(A)))/(N))
>>> imp = (1/(PrN))
>>> print(imp)
6.249999999999999


Gyroman 10-07-2019 03:39 PM

Quote:

Originally Posted by teckk (Post 6044620)
Whole thing is a mess.

Code:

>>> A = 5
>>> N = 2
>>> PrN = ((1/(A))*((N)-((N)/(A)))/(N))
>>> imp = (1/(PrN))
>>> print(imp)
6.249999999999999


Yes it was a mess but brackets around individual variables are unnesessary and confusing..

PrN = (1/A)*((N-N/A)/N)

works fine thank you.


All times are GMT -5. The time now is 11:24 AM.