Exam 1

2 minute read

Type: Individual Assignment
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:")

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:

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 8.74.

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 : (num) Input 2: (mult) Output
17 3 18
725.3 100 700
-123.7 25 -125

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:

New York City Landscape

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:

  1. Your program must have the following form:
# A program that shows a beautiful landscape to the user
# Authors:
from graphics import *

def main():
    # Your program goes here

  1. When I run your program, it should show me the landscape in a GraphWin window without any input from the user.

Note: 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.