我大约4天前开始学习python。为了练习,我决定编写一个计算组合的程序。
代码如下:
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)
运行此命令后,出现以下错误:
print(res)
^
SyntaxError: invalid syntax
>>>
然而,我看不出我在这里做错了什么。我想我可能在数学和函数上有问题,但是我不知道在这种情况下语法是怎么回事。
嘿,没什么好担心的,只是一个缺少括号的打字错误希望你能找到解决办法:)
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))
嘿,在下一行:
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))
你少了一个右括号。
您没有关闭res
行中的所有括号。试试这个:
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1]))*fator(exemplo[1]))