CS21 Lab 1: First programs

Due Saturday, February 3, before midnight


Make sure all programs are saved to your cs21/labs/01 directory! Files outside that directory will not be graded.

$ update21
$ cd ~/cs21/labs/01/
$ pwd
/home/username/cs21/labs/01
$ ls
countdown.py
salespitch.py
taxi.py
QUESTIONS-01.txt

Programming Tips

As you write your first programs, start using good programming practices now:


1. Sales Pitch Generator

You are in charge of writing sales pitches for startups looking for funding. Rather than learn about the product, you will write a program in salespitch.py that asks the user for some key words about the product (the technology, a model company, and the industry) and then output a short pitch (i.e., a venture-capital madlibs).

Here are two examples (user input in bold):

$ python3 salespitch.py
Technology: AI
Company: Google
Industry: face recognition

Our revolutionary AI
is a can't-miss opportunity.
We are the next Google
but for face recognition ... invest today!

$ python3 salespitch.py
Technology: plastics
Company: Uber
Industry: toilets

Our revolutionary plastics
is a can't-miss opportunity.
We are the next Uber
but for toilets ... invest today!

2. Ride Share

In taxi.py, write a simple program that simulates a ride-sharing app that calculates fees for each rider on a trip. Your program will ask the user for the miles traveled, the number of passengers, and the tip (as a percent).
You charge $1.25 per mile and $2.00 per passenger. You will output the subtotal (mileage and passenger costs), the total (after tip), and then the per-passenger cost.

Here are two quick examples (user input in bold):

$ python3 taxi.py
Miles traveled: 12
Passengers: 1
Tip (%): 20
--------------------------------
Subtotal: $ 17.0
Total: $ 20.4
Per Passenger: $ 20.4

$ python3 taxi.py
Miles traveled: 96.5
Passengers: 4
Tip (%): 18
--------------------------------
Subtotal: $ 128.625
Total: $ 151.7775
Per Passenger: $ 37.944375

You do not have to worry about having an even number of pennies (i.e., exactly two decimal places). We will learn how to do that later in the semester. You should assume that the passengers are whole numbers (integers), but the other two values are real valued.


3. Countdown Clock

In countdown.py, you will write a program to help procrastinate motivate you to work on your labs. You will ask the user for the time (as a 24-hour clock) and the number of days before the Saturday due date. You will then output the time remaining (due time is 23:59 on the due date) in two different ways. First, you will report a countdown clock as integer values of days, hours, and minutes remaining. Then, you will output the time remaining in terms of total days, total hours, and total minutes. You may assume that all inputs are integer valued.

Here is an example where it is 6:23pm (18:23) on the due date (user input in bold):

$ python3 countdown.py
Days until Saturday: 0
Current time (hour): 18
Current time (minute): 23

Countdown clock:
0 days, 5 hours, 36 minutes

Time remaining:
0.23333333333333334 days OR
5.6 hours OR
336 minutes

and another where the time is 6:00am, 4 days before the deadline:

$ python3 countdown.py
Days until Saturday: 4
Current time (hour): 6
Current time (minute): 00

Countdown clock:
4 days, 17 hours, 59 minutes

Time remaining:
4.749305555555555 days OR
113.98333333333333 hours OR
6839 minutes

4. Answer the Questionnaire

Each lab has a short questionnaire at the end. Please edit the QUESTIONS-01.txt file in your cs21/labs/01 directory and answer the questions in that file.


Turning in Your Labs

Don’t forget to run handin21 to turn in your lab files! You may run handin21 as many times as you want. Each time it will turn in any new work. We recommend running handin21 after you complete each program or after you complete significant work on any one program.