为什么我的返回数字在括号中?

时间:2018-01-30 22:33:14

标签: python python-2.7

当我运行我的代码时,返回的数字在括号中

像这样:你的目标心率区是:(125,144)每分钟节拍

我知道这是双重的,但不是如何避免这种情况。 任何人都知道如何解决?

def target (rate):
    print "Please indicate your exercise objective as follows"
    print "1 = weight loss, building endurance"
    print "2 = weight management, improving cardio fitness "
    print "3 = interval workouts"

    zone = int(raw_input("input your objective: ")) 
    if zone == 1:
        down = int(rate * .6)
        up = int(rate * .7)
        print down, up
        return down, up
    elif zone == 2:
        down = int(rate * .7)
        up = int(rate * .8)
        return down, up
    elif zone == 3:
        down = 0
        up = int(rate * .8)
        return down, up
print "This program calculates Maximum Heart Rate (MHR)  and preferred 
Target Heart Rate (THR) Zones "
print

age = int(raw_input("Please input your age: "))

mhr = 220-age

thr = target(mhr)

print "Your Target Heart Rate zone is: ", thr,  " beats per minute"

解决方案应该是:

Your Target Heart Rate zone is: # - # beats per minute

2 个答案:

答案 0 :(得分:0)

它实际上是tuple

为了更愉快地打印它,您将要单独格式化这两个数字。

print "Your Target Heart Rate zone is: ", thr[0], "-", thr[1],  " beats per minute"

答案 1 :(得分:0)

这是Python打印tuples的方式。

以下是如何获得所需的输出:

您可以使用方括号运算符获取元组的每个元素:

  • thr[0]是第一个值
  • thr[1]是第二个值

然后,您可以将这些值连接到字符串,如下所示:

print "Your Target Heart Rate zone is: " + thr[0] + " - " + thr[1] +  " beats per minute"