Becca's Chapter 5 Exercises

by Becca Greenstein

03 Feb 2016

Here is Exercise 1:

Here is Exercise 2:

Exercise 1 Thoughts: This one took me a while. First I had to figure out the proper order of the ifs, try/except, and while loop. I needed to put the if and break statement before turning the input into a float. I screwed up my indentation in the try conditional. At one point, it took inputs but always printed the error message in the except loop.

Then I got stuck and went to sleep. The next day, I tried it again with functions, but it was printing something like and I couldn't figure out why. The weird input messages were still occurring. I attempted to use global x for the first time, but no dice.

I then looked ahead on the schedule and saw that Chapter 8 is about lists. This looked promising. Midway through the chapter, I saw a part about remaking the original summing program and thought that might be useful. I used that to help me write my program.

The one thing I am still confused about is why you need to make a new name for the input for the user. I called it x and then had to give it a new name (value). When I didn’t do this, I had the error messages. I don’t remember doing this in the past.

Exercise 2 Thoughts: I could not come up with a way to do this without lists. So I used one, and based the rest of the code on Exercise 1. This one took a lot less time.

Becca is a second-semester MSLS student in SILS. She likes science, words, the outdoors, and helping people. Find Becca Greenstein on Twitter, Github, and on the web.