This lab assignment requires you to write three programs in Python. First, run update21. This will create the cs21/labs/01 directory (if you haven't already) and copy over any starting-point files for your programs. Next, move into your cs21/labs/01 directory and begin working on the Python programs for this lab. The pwd command helps you verify that you are in the correct sub-directory.
$ update21 $ cd cs21/labs/01 $ pwd /home/your_user_name/cs21/labs/01We will only grade files submitted by handin21 in this directory, so make sure your programs are in this directory!
As you write your first programs, start using good programming practices now:
This year we are using a free online textbook for the course. The money saved from buying an outrageously expensive textbook could be used to purchase something more interesting. Write a program that asks the user for the amount of money saved from not having to buy a textbook. Next, prompt the user to type something else he/she would like to purchase, as well as the purchase price of the item. Your program should then print how many of the desired item one could purchase with the textbook savings. Here are some sample runs showing how your program should work:
$ python booksavings.py Enter textbook savings: 75.25 What would you like to purchase instead of a book: coffee Enter item cost: 1.50 You could buy 50 coffee(s) with the textbook savings
$ python booksavings.py Enter textbook savings: 125 What would you like to purchase instead of a book: goat Enter item cost: 55 You could buy 2 goats(s) with the textbook savings
$ python booksavings.py Enter textbook savings: 80 What would you like to purchase instead of a book: Toyota Tacoma Enter item cost: 32000 You could buy 0 Toyota Tacoma(s) with the textbook savings
Write a program to compute the cost of a multi-day trip for one or more people. Your program should first prompt the user for the travel cost per person. Assume that the travel cost is a plane/bus/train ticket cost that each person must pay. Next, prompt the user for the food and lodging cost per day. Next, ask the user for the number of days of the trip and the number of people traveling. Your program should compute and print the total cost per person for the trip including travel, food, and lodging. Finally print the total cost for the group. Assume that food and lodging are paid for each day of the trip, but the travel cost is only paid once, regardless of trip length. Some sample runs of the program are shown below.
$ python tripcost.py Let's go on a trip What is the travel cost per person?: 400 What is the food/lodging cost per person per day?: 135 How many days will you be traveling? 5 How many people are going? 2 Cost per person $1075.00 Total cost $2150.00
$ python tripcost.py Let's go on a trip What is the travel cost per person?: 40 What is the food/lodging cost per person per day?: 30 How many days will you be traveling? 2 How many people are going? 4 Cost per person $100.00 Total cost $400.00
Below are some sample runs showing how your program should work.
$ python drivetime.py Enter slowest speed in mph: 40 Enter fastest speed in mph: 60 Enter driving distance in miles: 100 Time chart for 100 miles speed time --------------- 40 2.50 hrs 41 2.44 hrs 42 2.38 hrs 43 2.33 hrs 44 2.27 hrs 45 2.22 hrs 46 2.17 hrs 47 2.13 hrs 48 2.08 hrs 49 2.04 hrs 50 2.00 hrs 51 1.96 hrs 52 1.92 hrs 53 1.89 hrs 54 1.85 hrs 55 1.82 hrs 56 1.79 hrs 57 1.75 hrs 58 1.72 hrs 59 1.69 hrs 60 1.67 hrs
$ python drivetime.py Enter slowest speed in mph: 25 Enter fastest speed in mph: 30 Enter driving distance in miles: 45 Time chart for 45 miles speed time --------------- 25 1.80 hrs 26 1.73 hrs 27 1.67 hrs 28 1.61 hrs 29 1.55 hrs 30 1.50 hrs
$ python drivetime_extra.py Enter slowest speed in mph: 25 Enter fastest speed in mph: 30 Enter driving distance in miles: 45 Time chart for 45 miles speed time --------------- 25 1:48 hrs 26 1:43 hrs 27 1:40 hrs 28 1:36 hrs 29 1:33 hrs 30 1:30 hrs
Remember you may run handin21 as many times as you like. Each time you run it new versions of your files will be submitted. Running handin21 after you finish a program, after any major changes are made, and at the end of the day (before you log out) is a good habit to get into.