Homework 4: While Loops

Due: Monday, September 29

This is the first homework that uses CodingBat, an online place to practice writing code with immediate feedback. You will need to make a free account:

  • Go to codingbat.com
  • Follow the instructions to make an account – please use your Hendrix email as your account ID
  • You can use any password you like
  • Under the prefs tab (top right, next to your name), enter your professor’s email in the Teacher Share Box (seme@hendrix.edu or yorgey@hendrix.edu)

Complete at least five of the following exercises in CodingBat.

In addition, for the following two code snippets:

  • Predict: First, complete the exercise without using the Python interpreter.

  • Check: Run the code in a Kaggle notebook or PyCharm. Does the actual output agree with what you wrote down in step 1?

  • Evaluate: If your answer in step 1 was different than the actual output, keep experimenting with it, consult an online reference, ask a friend or TA or professor, etc. until you can explain why the code works the way it does and what your misunderstanding(s) were in part 1.

  1. Write down everything that is printed:

     n = 5
     i = 0
     while i < n:
       print(i * n)
       i += 1
    
  2. What is the value of s after the code is run?

     s = 5
     i = 0
     while i < 6:
       s += (i ** 2)
       i += 2