A201 Introduction to Programming 1

A201 Homework 4

Due Date: Tuesday, September 19, 2023.

Goal: to use while loops in Python.

Make sure to complete Lab 4 before doing the homework.

Create a Python script file called hw4.py. Add your name at the top as a comment, along with the class name and date. Both exercises should be in this file, with a comment before each of them to mark it.

Ex. 1.

Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it.

Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0.

Ex. 2. Magic 8 ball

Write a program that works as an oracle similar to a magic 8-ball. The program should tell the user to ask a question, and input the answer in a variable. Then it should generate a random value between 1 and 8, and print a message. Then it should ask the user if they want to ask another question, with possible answers "yes" and "no". The program should repeat the operation until the user enters "no".

The possible answers to the magic 8-ball should contain "You can count on it", "My sources say no", "Concentrate and ask again", "Very doubtful", and 4 others that are left up to you.

Homework Submission

Upload the files lab4.py and hw4.py in Canvas, Assignments, Homework 4.