Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Assignment 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Assignment

2
Assignment due Saturday, November 5, 2022 by
11:00pm
Overview. This assignment will allow you to practice algorithmic thinking and basic Python
programming with several small-scale problems. As you solve each problem, follow the steps of
algorithmic thinking as outlined below. Use this template to complete the assignment.
• Step 1: Algorithm Description. Include a step-by-step algorithm accompanied by either
a flowchart or a Pseudo code to develop and express your steps that accomplish the
given task . Remember, you have to be very explicit and clear to make sure one can
actually achieve the task following your directions. Describe the input(s), output(s) and
the process of the algorithm.
NOTE: To import a picture, for example, “image.png” to your Jupyter notebook, you can use the
following block of code from IPython.display import ImageImage("my_image.png")
• **Step 2: Program Code – Implementation: **Implement the algorithm in Python using
the basic structures we covered in class (feel free to use additional ones):
• User input
• Variables
• Operators
• Conditional execution
• Functions
• Modules
• Data structures: Lists, strings, tuples, sets, dictionaries
• **Step 3: Program Testing: **Create a Test Plan with enough test cases that demonstrate
your code works as intended. Explain how you used these test cases in your comments.
• **Step 4: Program Documentation: **Be sure to comment thoroughly so that it is clear
that you understand what every line of the code is intended to accomplish.
Problems

**Problem 1. **Write a function to calculate the cost of a trip to a theme park, which includes
the cost of the hotel, car rental, and park tickets.

a. Define a function to calculate the cost of the hotel. The function should allow the user to
choose one of the room types below and enter the length of their stay. The function then
calculates the cost accordingly.

Standard room: 150$ per night

Deluxe room: 180$ per night

Suite: 220$ per night

b. Define another function to calculate the cost of renting a car. Rental cars charge
100$ up to 24 hours and 60$ added for each additional day.

c. Define a third function to calculate the cost of parking at the theme park. The cost of parking
is 175$ for the first day and 50$ for each additional day.

d. Your final function should calculate the total cost of the theme park trip by calling the three
functions above and summing their results.

Problem 2.

Write a function that asks the user to enter their exam scores in their History, Math, Language
Arts, and Social Science classes and save the scores in a dictionary.

Example.
{“History”: [56, 75, 25], “Math”: [75, 85, 95, 65], “Language Arts”: [43, 32, 25], “Social
Studies”: [90, 100, 95, 80]}

Return the user the two following dictionaries:

1. Calculate the average score for each class and save it in a new dictionary.
2. Next convert the average scores into letter grades based on the following scale and save
the letter grades in another dictionary.
score > 90: A
75 < score <= 90: B

60 < score <= 75: C

score <= 60: D

Problem 3.

Write a function that accepts positive integers until the user enters “quit” and splits the numbers
into three lists: the first one contains all the numbers, the second one contains all even numbers,
and the third one contains all odd numbers. The function should return all three lists as well as
the minimum and the maximum numbers in each list.

Your function should prompt the user to enter a positive number if they enter a negative value.
Your assignment submission needs to include the following resources:

1. A .pdf file must be the first resource and it will include all the answers to the questions
above, including all the python code you produce. Make sure that you submit a neat,
clearly presented, and easy-to-read .pdf. The .pdf should be submitted under the name file
“student_name.pdf”.
2. Your second resource must be a single Jupyter Notebook with extension .ipynb (please
see Figure below) and named “student_name.ipynb”. Zip your .pdf and .ipynb files.
***You need to submit two files: (1) pdf file from the first step and (2) the zip file from the
second step.

Assignment Information
Weight:
20%
Learning Outcomes Added
• ComputationalTools: Apply the computational terminology and tools appropriately in
different quantitative contexts.
• AlgorithmicStrategies: Demonstrate the ability to think logically and systematically about
problems, breaking them down into a clear, ordered set of concrete steps that could be
implemented by a machine.
• CompProgramDesign: Generate working programs in a computer language that can solve
computational problems; find and fix bugs that appear in them.
• QuantCommunication: Communicate with a clear and precise style that is suited to an
appropriate audience. Produce code that can be easily read and understood by others.

You might also like