Please review this week’s handouts (handout #1, #2, and #3) before starting on this homework. To submit your solution, compress all your .py files together into one zip file. Login to handins.ccs.neu.edu with your Khoury account, click on the appropriate assignment, and upload the zip file. You may submit multiple times until the deadline; we will grade only the most recent submission.
Your solution will be evaluated according to our grading rubric (https://course.ccs.neu.edu/ds2000/ds2000rubric.pdf). The written component accounts for 20% of your overall HW1 score; the programming component for 80%. We’ll give written feedback when appropriate as well; please come to office hours with any questions about grading.
You are permitted two “late day” passes in the semester; each one allows you submit a homework up to 24 hours late. You may apply both to this homework, or split them between two homeworks. The Hand-in Server automatically applies one late-day token for every 24 hours (or part of 24 hours) you submit past the deadline.
This is an introductory course, and we want to make sure that everyone has a solid understanding of the fundamentals, so we’ll often rule some Python tools in or out. For this homework we’re focusing on variables and arithmetic operations; do not use conditionals, lists, tuples, or loops.
Written Component (20% of your homework score)
Please open a plaintext file (you can do this in IDLE or any plaintext editor you like, such as TextEdit or NotePad) and type out your answers to the questions below. You can type your answers into Python to confirm, but answer the questions first!
Written #1
What are the data types of the following values?
1A 48.25
1B 48
1C -1
1D -5.0
1E "hello"
1F 'and goodbye!'
1G '15'
Written #2
What do the following expressions evaluate to?
2A 7 / 5
2B 7.0 / 5.0
2C 7 // 5
2D 7 % 5
Written #3
I’ve just opened up my Python terminal and typed the following 3 statements, all using the print function. In your own words, explain why the third one would give me an error:
Programming Component (80% of your homework score)
Code Structure and Style
A percentage of your score for every homework is for writing good, clear, readable code. For HW1, focus on comments and variables. Read the style guide sections on those topics, and make sure your comments and variables are helping to make your code nicely written.
Before you write any other code, type def main(): at the very top of your file (underneath your block comment with name, assignment, etc.) and main() at the very bottom. Your program’s code will go in between.
''' DS2000 Name Here HW1 Jan 17, 2020 '''
def main(): # Your code goes here! # Make sure you indent one tab to the right
main() |
Programming #1
Cheesy Joe’s Currency Exchange converts US Dollars to Wizarding Money. For each conversion, they charge a flat fee plus 3% of the amount converted. For instance, the total charge for converting 350 US dollars to Sickles and Knuts is
Write a program that prompts the user for a US currency value, and tells them the total amount charged to do the conversion. (Part of your job is to figure out the flat fee.)
Your output should be formatted the way we’d expect currency to look, like $100.00 or $6.90. You can assume that the user enters a valid input.
Before you begin coding -- write test cases!
In the comments at the top of your file, list 3 test cases that you came up with. Something like this, but choose your own examples. You should write your test cases in such a way that, if they all pass, you can be fairly confident your program will work all the time.
'''
Test case #1:
Input: $350
Total fee: $15.00
Test case #2:
Input: $80
Total fee: $6.90
'''
AMAZING points: These final two points may be awarded if you’ve completed the rest of the assignment perfectly and blown us away with...
Example Output
Programming #2
You and your friends have just run a road race, congratulations! The race took place in beautiful downtown Vancouver. There were a bunch of different distance options, so some of your friends ran a 10k, some ran a 5k, and some of them even ran a 50k or more! How many miles are those distances? They didn’t say, because Canada.
No matter the distance, though, we have finishing times in hours and minutes.
So you have a distance (in kilometers) and a finish time (in hours & minutes), and you want to calculate and report back three things:
Write a python program that will figure this out for you and your running buddies. Your program should prompt the user for three inputs:
You can use any wording you like to gather information for the user, it doesn’t have to match our example below. However, the order in which you prompt them must be the same. For grading, we test your code using auto-generated input in a specific order. Ask the user for (1) distance, then (2) hours, then (3) minutes.
Before you begin coding -- write test cases!
In the comments at the top of your file, list 3 test cases that you came up with. Something like this, but choose your own examples, and make sure you have a few edge cases in there -- make sure your test for a very long / very short race, a distance like .1 kilometers, etc.:
'''
Test case #1:
10k race, 1 hour and 1 minute:
6.21 miles, 9:49 pace, 6.11 MPH
Test case #2:
25k race, 2 hours and 13 minutes:
15.53 miles, 8:34 pace, 7.01 MPH
'''
Helpful hints:
>>> rounded = round(5.88888, 3)
>>> rounded
AMAZING points: These final two points may be awarded if you’ve completed the rest of the assignment perfectly and blown us away with...
Example Output
Programming #3
Archimedes was a Greek mathematician, philosopher, and cartoon owl, and one of his big contributions to mathematics was his method to approximate the value of . We’ve all used to calculate the circumference of a circle, because . If the radius of the circle is one, it’s easy to solve for .
We’re going to implement a version of Archimedes’s approximation by calculating the perimeter of a polygon that inscribes a circle with radius 1. That perimeter, divided by 2, gives us ; the more sides the polygon has, the closer it is to being an actual circle, and the more accurate the calculation is.
Write a Python program that prompts the user for a whole number; this will be the number of sides of the polygon. Use that number to approximate and report using the algorithm described below.
We calculate the perimeter of a polygon using the following algorithm:
Helpful hints:
AMAZING points: These final two points may be awarded if you’ve completed the rest of the assignment perfectly and blown us away with...