-1

When I run my code, the returned numbers are in parentheses

Like this: Your Target Heart Rate zone is: (125, 144) beats per minute

I know that this is a duple, but not how to avoid this. Anyone know how to fix?

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"

The solution should be :

Your Target Heart Rate zone is: # - # beats per minute
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
Christian
  • 37
  • 2
  • A possible solution: return a string where you concatenate down, " - " and up. It does make it less flexible of a solution, though. – Chris Forrence Jan 30 '18 at 22:35
  • 4
    You are returning a tuple in the `target` function. So what did you expect? How about changing the print to `"Your Target Heart Rate zone is between ", thr[0]," and ", thr[1], " beats per minute"` ? – excalibur1491 Jan 30 '18 at 22:36

2 Answers2

0

It's actually a tuple.

To print it more pleasantly you'll want to format the two numbers individually.

print "Your Target Heart Rate zone is: ", thr[0], "-", thr[1],  " beats per minute"
Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169
0

This is the way Python prints tuples.

Here's how to get the output you want:

You can get each element of your tuple with the square brackets operator:

  • thr[0] is the first value
  • thr[1] is the second value

You can then concatenate those values to your string, like this:

print "Your Target Heart Rate zone is: " + thr[0] + " - " + thr[1] +  " beats per minute"
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56