Homework

Name:

Instructions

In your private course repo on Rivanna, write a Jupyter notebook running Python that performs the numbered tasks below.

For each task, create a code cell to perform the task.

Save your notebook in the M03 directory as hw03.ipynb.

Add and commit these files to your repo.

Then push your commits to your repo on GitHib.

Be sure to fill out the Student Info block above.

To submit your homework, save the notebook as a PDF and upload it to GradeScope, following the instructions.

12 points

Task 1

(6 points)

Using the for loop and if statement control structures, write a script that generates the integers from \(1\) to \(100\) and does the following things:

  • If \(3\) is a factor of the number, print Wahoo.
  • If \(5\) is a factor of the number, print wah!.
  • If the number meets none of the above conditions, print nothing, not even a line break.
  • If the number meets both of the conditions, print the strings on the same line with no space between them.
  • Make sure that the line printed for each iteration in which a condition is met ends with a line break.
  • When the loop is finished, print the number of times either conidtion was met, i.e. the number of lines that were printed.

Hint: You may not need to use elif and else to accomplish these tasks.

# CODE

Task 2

(3 points)

Rewrite the for loop as a while loop.

This time, only print lines where both conditions are met.

Include a final line which prints the number of times both conditions are met.

# CODE

Task 3

(3 points)

Write a list comprehension that iterates through the integers from \(1\) to \(100\) and returns a list containing the sum of the boolean values of the two conditions described in Task 1.

# CODE