Due: before class on Thursday, February 25, 2021
Before You Begin
Start by reading the exam procedures page. It covers important policies that are in place during an exam week.
Problem 1: Tip Calculator
In the U.S., when eating at a restaurant, it is customary to give your server a tip which is a percentage of the total bill.
Below is the skeleton of a Python program that computes this total bill.
# A program that asks the user for the total bill # along with how much they want to tip, and then # outputs the total bill including the tip. # # Author: # Titus Klinge and YOUR NAME GOES HERE bill = float(input("Enter the total bill as a float: ")) tip = int(input("Enter your percent tip as an int: ")) bill_with_tip = # TODO: write an expression here print("The total bill (including your tip) is:") print(bill_with_tip)
Copy and paste this code into a file named
calculate_tip.py and replace the
TODO comment with an expression to complete the program.
When you run the program, it should work like the following if the user types in
7.60 as the bill and
15 as the tip
Enter the total bill as a float: 7.60 Enter your percent tip as an int: 15 The total bill (including your tip) is: 8.739999999999998
Note: A modicum of extra credit will be awarded if you round the final answer to two decimal places so that the above example would print
Problem 2: Nearest Multiple
Write a program called
nearest_multiple.py that asks the user to input a number (here I will call it
num) and a strictly positive integer (here I will call it
mult) and prints as output the closest integer to
num that is a multiple of
mult. Below are some example inputs and corresponding outputs.
|Input1 : (
||Input 2: (
For example, running your program might look like the following:
Enter a decimal number (float): -123.7 Enter a positive whole number (int): 25 -123.7, rounded to the nearest multiple of 25, is -125
Problem 3: Graphics Landscape
Write a complete Python program named
landscape.py that utilizes Zelle’s graphics library to produce a scene of a landscape. Below is an example landscape I modeled after a picture I found of New York City:
You have complete creative control over what landscape you choose to make. You could make a fall scene with trees and leaves, or a winter scene with snowmen, or a countryside with dirt roads and badly drawn animals.
Note that your landscape scene does not need to be exceptionally detailed, for example, the buildings above are just rectangles and the clouds are just composed of three circles. However, your solution must satisfy the following constraints:
- Your program must have the following form:
# A program that shows a beautiful landscape to the user # # Authors: # YOUR NAME GOES HERE from graphics import * def main(): # Your program goes here main()
- When I run your program, it should show me the landscape in a
GraphWinwindow without any input from the user.
Your landscape does NOT need to have as many objects as the one I included above. I cheated and used a
for loop to generate the rectangles and circles with relatively few lines of code (because it was fun). You are just expected to familiarize yourself with the graphics library and make something cool looking.