[英]Printing Comments in Python with integers
def triangular(n):
tri = 0
for i in range(1, n+1):
tri = tri + i
print ("The answer is equal to" +(tri))
triangular(4)
I just need help with the print statement because it doesn't work. 我只需要有关打印语句的帮助,因为它不起作用。 I am trying to print the answer is equal to tri 我正在尝试打印答案等于三
You need to cast your int
to a str
. 您需要将int
转换为str
。
# str is optional here because print will call str on its arguments for you
print("The answer is equal to", str(i))
or 要么
# str is not optional here because you are concatenating
print("The answer is equal to " + str(i))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.