r/pythonhelp • • Dec 17 '21

Newbie Code Question

Hi, im a Crossfitter and always want to workout the halfway point of some workouts, so im trying to make something that does this for me as practice for python, which im very new to. the code works but it only prints halfway_round as the intial value of "undefined" and doesnt redefine it with the if statement. Why is this? As said, im very very new to coding so please dont trash this too much, im just trying to learn!

##Rep Scheme Halfway Calculatorreps_a = []reps_b = []total_a = 0total_ - Pastebin.com

3 Upvotes

8 comments sorted by

View all comments

1

u/carcigenicate Dec 17 '21

Double check the values of the r* variables, and halfway (put a print in that prints the values, or use a debugger).

If halfway_round is never reassigned, that means none of the halfway <= r* checks are true. Look at the data to figure out why that is.

1

u/[deleted] Dec 17 '21

Thanks. All of the r values are correct when printed before the if section.

1

u/carcigenicate Dec 17 '21

Then check halfway. Again, if it isn't reassigned, none of your conditions are true, which means either the conditions are wrong, or the data is wrong.

1

u/[deleted] Dec 18 '21

Hmm im still not getting it. I printed each R value. All correct. So yes, the variable halway_round is not getting reassigned. I chose a rep number that meant the halfway_round would be r2 and it DID match this, however halfway_round was NOT reassigned despite meeting the <=r2 criteria

1

u/carcigenicate Dec 18 '21

That's not possible. If halfway <= r2 is true, that variable will be reassigned. Guaranteed. If it isn't, you're misinterpreting your data.

And I can't reproduce. Note this session:

What are the start reps for part A?5
How many reps does part A decrease by?2
What are the start reps for part B?5
How many reps does part B decrease by?2
How many rounds is the workout split into?5
The halfway point is at 0.0 reps which is in Round 1

Since "Round 1" is printed, halfway_round is indeed being reassigned, as expected.

1

u/[deleted] Dec 18 '21

Hmm, the numbers I used, based on the workout I did yesterday were:

50

10

25

5

5

1

u/carcigenicate Dec 18 '21 edited Dec 18 '21

Like I said, double check your data. With that input, if I put print(halfway, r1, r2, r3, r4, r5) before the if tree, I get 112.5 75 60 45 30 15 printed to the console. Since 112.5 is greater than all of the other numbers, none of your conditions are true, so halfway_round is never reassigned.


If the condition is true, the body will execute. If the body doesn't execute, the condition was false. No exceptions. It's your job then to figure out why the condition was false.

That means your logic is incorrect and you need to re-evaluate the equations you're using.

1

u/[deleted] Dec 18 '21 edited Dec 18 '21

Thank you! Very much appreciate your patience; im a total beginner. I should be adding r1 to r2 etc to keep a running total, not sectioning them off into individual rounds

This works;

if halfway <= r1: halfway_round = "Round 1" elif halfway <= r2 + r1: halfway_round = "Round 2" elif halfway <= r3 + r2 + r1: halfway_round = "Round 3" elif halfway <= r4 + r3 + r2 + r1: halfway_round = "Round 4" elif halfway <= r5 + r4 + r3 + r2 + r1: halfway_round = "Round 5"