Home > Enterprise >  Having trouble with python3 print syntax
Having trouble with python3 print syntax

Time:11-20

I've started to learn python about 4 days ago. To practice, I've decided to make a program that calculates combinations.

Here is the code:

print('Insert values for your combination (Cp,n)')
def combin(exemplo):
    print('insert p value')
    p = int(input())
    print('insert n value')
    n = int(input())
    exemplo = [p,n]
    #"fator" is a function defined earlier in the program. It basically calculates the factorial of a number
    res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))
    print(res)

teste = []
combin(teste)

After running this, the following error has ocurred:

print(res)
    ^
SyntaxError: invalid syntax
>>> 

However, I can't see what I'm doing wrong here. I figured that I probably would have problems with the math and the functions, but I can't figure out what's up with the syntax in this case.

CodePudding user response:

Hey nothing to worry about, its just a typo with missing parenthesis hope you find the solution :)

res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))

CodePudding user response:

Hey in the following line:

res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))

you are missing a closing bracket.

CodePudding user response:

You didn't close all of your parenthesis in the res line. Try this:

res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1]))*fator(exemplo[1]))
  • Related