HNRS 299, Spring 2017

    Assignments

    HNRS 299 Python Homework 1

    Due Tuesday, February 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

    Sample sessions running a completed version of the homework program:

    Session 1:

     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.
     
    

    Session 2:

     Hi there!  What is your name? Dorothy
     Where are you going? the Emerald City
     How far have you traveled (in miles)? 2
    
     Let me see if I have this straight:
     Dorothy has traveled 10560 feet on the way to the Emerald City.
    
     Thanks for running the program.
     
    

    Explanation of the program

    In the above example, the underlined items are user 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 first 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, the user input is underlined. You should not worry about the number of decimal places printed for this particular problem, but the tips should be the correct amount for whatever the user inputs.


    What you will turn in:

    • A printout showing the Python code for each of your programs. Be sure that your listing has comments with the program name, your name, the date, the course number and your section, the assignment number, and the purpose of the program.
    • A printout showing a run of each of the programs.
    • Print your name at the top of the cover page and staple it to the top of your hard copy.