MONT 105S, Spring 2009

Home | | Course Schedule | | Assignments | | Lecture Notes

MONT 105S Homework 2

Due Wednesday, January 28, at the beginning of class.

Problem 1

You've probably gotten form letters written by computer, which fill in your name in the body of the letter in an attempt to make them seem personal. In this assignment we write a program which could be used for such a mailing, except instead of a whole long letter, we're just printing out a few lines.

You will write a program which administers a questionaire, then prints back a few sentences using the information it got from you. The program will be written in the Python language, and it will use variables to keep the information it collects.

Name this program journey.py

A Sample session running a completed version of the homework program

 Hi there!  What is your name? Frodo Baggins
 Where are you going? Mount Doom
 How far have you traveled (in miles)? 10

 Let me see if I have this straight:
 Frodo Baggins has traveled 52800 feet on the way to Mount Doom.

 Thanks for running the program.
 

Explanation of the program

In the above example, the underlined items are user input. Note that when you run your python program, the user input will be on the same line as the question requesting the input. The idea is that the person running the program (which might not be you) answers the three questions, and then the computer fits the answers into its sentence. Note that for this example to work, the user has to answer in a particular form. If the user had answered 'to Mount Doom' in response to the second question, the program would print out 'Frodo Baggins has traveled 52800 feet on the way to to Mount Doom.' More advanced programs can check for this kind of thing and correct for it, but you don't have to worry about it for this assignment. Note also that the computer converts the distance from miles to feet. Recall that 1 mile is 5280 feet. Your program should print out the number of feet that corresponds to the number of miles that the user inputs.


Problem 2

Write a program to calculate the tip on a restaurant bill. The program should prompt for the amount of the bill, and then print out the two amounts, one for a 15% tip and one for a 20% tip.

Name this program tipComputer.py.

A sample session might look like this:

Please enter the amount of the bill: 15.34
A 15% tip would be $ 2.301
A 20% tip would be $ 3.068
As with the previous program, when you run your python program, the user input will be on the same line as the question requesting the input. You should not worry about the number of decimal places printed for this particular problem.


What you will turn in: