Help with bug in his code!

Victor C

Notice he has a bug with “Nightmare button”
and he plans on using this as his AP create project.

Any idea why “nightmare” button does not re-set correctly?

Hi @mschlager,

Because this is a student’s AP Create PT, he is not allowed to receive any feedback - including from other students, his teacher, or members of this community. Students must debug their code independently.

You can, however, teach the class general debugging strategies, which the student may implement and possibly help him discover and fix the bug.

Frank

Ok - thank goodness for you!
Frank, I am feeling less than smart. I can not wrap my brain around this! Unit 5 - Lesson 12 - bubble 8.
What the heck is the goal here?? to get 12 heads in a row would take thousands of flips I would think.
Below is straight out of the instructions.
We are going to alter our simulation so that it doesn’t count the total number of heads, but rather the longest streaks of heads . This will allow us to simulate how many flips it takes to get 12 heads in a row .
I am absolutely missing the big picture here (though I did code it correctly).
What is this showing me? Can not get 12 heads in a row out of 20 or 30 flips.
Of course, cannot get 12 heads out of 10 flips…
Confused!

what I am thinking is heads, heads, heads, heads, heads, heads, heads, heads, heads, heads, heads, heads in a row. (no tails in between)

Your understanding is correct. The big problem students will solve is to get 12 streaks in a row. It will take a lot of tosses to get 12 streaks and it will be hard to test the program, so students are advised to test the program for 10 tosses and to print the toss and the streak count. Once the program seems to work, the loop count can be increased to 1000 and all tosses do not need to be printed to the screen.

The sample run that you see, is printing the toss (0 or 1) and the number of streaks. So the first toss is a 1 (head), so the heads streak is 1, but then the toss is a 0 (tail), so the heads streak is set back to 0. The next toss is another 0, so the heads streak is still 0, in the fourth toss we get a head, and the streak count is incremented to 1 and so on.

Through the various code studio levels, students are taught how to try to solve a smaller problem and then modify it to solve the bigger problem. I hope this makes sense.

Are you saying that 1 toss of heads can be considered a streak? What about this one? Is Heads streak: 5 a part of the streak or the total?

And thank you. I get so frustrated when I can not make sense of things. I have been at this for hours already.

All they are doing is printing the streak count to make sure it is working. So the 1 is the number of streaks so far and 1 is showing up as a streak of 1 head. Before the “Heads Streak: 2” statement, there are two 1s printed and so on. There are 5 ones printed just before “Heads streak: 5”. So the streak count is 5.

Ok I get that - but I know my students will want to understand the answers the program gives. I would hate to say I do not understand it myself. Plus, I really do want to understand before I move on. I use videos with my students, so I started on one and hit a wall. Would you mind looking at it? Clearly I do not yet have it down. And thanks so much for your time and attention.
-Melanie link below…

CoinToss

Ok, I understand your confusion now. The big task the students are getting at (in level 10) is to stop the program once they get 12 heads in a row. So there is no need to count the number of streaks occurring, but to simply see when a streak of heads occurs. The “Heads streak” is not the total number of streaks, but the number of heads tossed in continuous tosses. Every time a tail is tossed, the streak is broken and hence the count is set to 0. Does this make sense?

By the way, thank you for your help.
OK - I am getting close. If that is so - why would I see 0 at line 9 and then a heads streak of 1 just below it? Is that just another coin flip result? There is no adding up anywhere of the Heads streak? That seems to be what you are saying. If so, I am good!

You are welcome!

Yes, you are right. It is another coin flip which is a 1, hence the heads streak is set to 1. After that another 1 is tossed and so the heads streak is set to 2 since we now have 2 heads in a row, and so on.

Hi @mschlager,

Think of the word “streak” as the phrase “in a row”. Thus, “Heads streak: 4” means you flipped 4 heads in a row.

What happens if you then flip a tails? That ruins your streak and the streak count resets, thus “Heads streak: 0”

It’s also confusing because there’s different numbers on the screen that represent different things. The 0 and 1 in-between the streak counts represent the individual coin flips - 1 is heads, 0 is tails.


In your image, here’s what’s happening:
Flipped HEADS - 1 head in a row
Flipped TAILS - (streak reset) 0 heads in a row
Flipped TAILS - (streak reset) 0 heads in a row
Flipped TAILS - (streak reset) 0 heads in a row
Flipped HEADS - 1 head in a row
Flipped HEADS - 2 heads in a row
Flipped HEADS - 3 heads in a row
Flipped HEADS - 4 heads in a row
Flipped TAILS - (streak reset) 0 heads in a row
Flipped HEADS - 1 head in a row

The program in this example did not stop when it was supposed to. Nowhere in the problem to do we care about the TOTAL number of heads, which seems to be what’s triggering the end of your program… we want it to end when the head STREAK reaches 12… this example only got up to a head streak of 4.

Well hi Frank! Nice to hear from you. I did move on to the next lesson and re-set the 10 to 3. But I do appreciate your illustration of what is happening. Extremely helpful. Moving on. It is summer and I learned just how much better I can be teaching CSP last year. Hope all is well with you and you have found your own gig. But don’t stop your code.org assisting. You and Sangeeta are awesome.

Just to clarify the total lesson… Step 8 is just step on the way to how many flips to get a steak of 12 in a row. The program isn’t done until step 10. Step 8 is simply can you count how many heads in a row if you roll the dice 10 times.