7.9. πŸ‘©β€πŸ’» Printing Intermediate ResultsΒΆ

In this textbook we provide the codelens tool so that you are able to step through the program and watch what happens each time a line is evaluated by the Python interpretor. What if you didn’t have codelens though, what would you do?

In that case, print statements are your best friend. They can show you what the value of something is. This is especially helpful in the case of writing for loops or accumulating a value. If something is going wrong you can compare what you expect to happen to what is actually happening.

Say we weren’t sure what num was being assigned each time we iterated. One way to find out would be to add a print statement inside of the for loop to see.

Before you keep reading...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

If we wanted to see what was happening to tot as well, we could print that out in the for loop as well!

Finally, if we wanted to make these numbers easier to understand, we could add more to the print statements to make them easier to read!

You have attempted 1 of 5 activities on this page