Reputation:
PROGRAM
I'm attempting to write a code which calculates the estimated fatigue level of an elite level weightlifter based on empirical data from various studies of Russian and American lifters.
All of these calculations are based on a lifters heaviest weight lifted. This isn't always so easily tested during training as max effort lifts severely hinders recovery due to their intensity. For that reason a part of the program has to be able to estimate a one repetition max based on a single set.
PROBLEM
'if' returns perfectly. All the elifs just print the decimals after * and loads menu(). I have tried experimenting with float() and int() but my programming ability seems to be lacking.
I'm also pretty sure that my writing is very inefficient (been coding for two weeks).
def repmax():
clear()
while True:
print "Weight lifted?\n"
weight = int(raw_input("> "))
print "\nRepetitions done?\n"
reps = int(raw_input("> "))
print "\n"
if reps == 1:
print "Your estimated 1RM is %s.\n" % weight * 1
menu()
elif reps == 2:
print "Your estimated 1RM is %s." % weight * 0,95
menu()
elif reps == 3:
print "Your estimated 1RM is %s." % weight * 0,90
menu()
elif reps == 4:
print "Your estimated 1RM is %s." % weight * 0,88
menu()
elif reps == 5:
print "Your estimated 1RM is %s." % weight * 0,86
menu()
Upvotes: 0
Views: 63
Reputation: 1121186
You have your floating point numbers wrong, use a decimal point instead of a comma:
print "Your estimated 1RM is %s." % (weight * 0.95)
Note that you need to put the calculation in parentheses; otherwise python will try to multiply the result of "Your estimated 1RM is %s." % weight
. Demo:
>>> "Your estimated 1RM is %s." % (weight * 0.95)
'Your estimated 1RM is 76.0.'
You can indeed optimise your code somewhat; use a list to map repetitions to factor:
reps_to_factor = [1, 0.95, 0.90, 0.88, 0.86]
Now you can just subtract one from reps
and get the right factor:
print "Your estimated 1RM is %s.\n" % (weight * reps_to_factor[reps - 1])
menu()
and no if..elif
structure is needed.
Upvotes: 1