使用整数在Python中打印注释

use*_*229 -1 python pretty-print

def triangular(n):
    tri = 0
    for i in range(1, n+1):
        tri = tri + i

    print ("The answer is equal to" +(tri))

triangular(4)
Run Code Online (Sandbox Code Playgroud)

我只是需要print语句的帮助,因为它不起作用.我试图打印答案等于三

wfl*_*nny 7

print("The answer is equal to", tri)
Run Code Online (Sandbox Code Playgroud)

要么

print("The answer is equal to %i"%tri)
Run Code Online (Sandbox Code Playgroud)

要么

print("The answer is equal to {}".format(tri))
Run Code Online (Sandbox Code Playgroud)

文档也有一些更多的方式来做到这一点.