[SOLVED] algorithm math python DS2000

$25

File Name: algorithm_math_python_DS2000.zip
File Size: 263.76 KB

5/5 - (1 vote)

DS2000
Spring 2020
HW1 data types and arithmetic operations
Assigned: January 10, 2020
Deadline: January 17, 2020 at 9:00am

Please review this weeks 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.eduds2000ds2000rubric.pdf. The written component accounts for 20 of your overall HW1 score; the programming component for 80. Well 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 Handin Server automatically applies one lateday 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 well often rule some Python tools in or out. For this homework were focusing on variables and arithmetic operations; do not use conditionals, lists, tuples, or loops.

Written Component 20 of your homework score
Filename: written.txt

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

1B48

1C1

1D 5.0

1Ehello

1Fand goodbye!

1G15

Written 2
What do the following expressions evaluate to?

2A75

2B7.05.0

2C75

2D75

Written 3
Ive 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 topof your file underneath your block comment with name, assignment, etc. and main at the very bottom. Your programs 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
Filename: currency.py

Cheesy Joes 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 wed expect currency to look, like 100.00 or 6.90. You can assume that the user enters a valid input.

Before you begin codingwrite 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 youve completed the rest of the assignment perfectly and blown us away with
Using constants where appropriate.
Using round or format functions only for printing out, and do not save any values that have been rounded off, floored, etc.

Example Output

Programming 2
Filename: racepace.py

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 didnt 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 hoursminutes, and you want to calculate and report back three things:
Miles the runner ran, converted from kilometers. Round to two significant digits.
Average pace per mile, in minutes and seconds.
Average miles per hour. Round to two significant digits.

Write a python program that will figure this out for you and your running buddies. Your program should prompt the user for three inputs:
Number of kilometers they ran, a float
Number of hours, a whole number
Number of minutes, a whole number

You can use any wording you like to gather information for the user, it doesnt 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 autogenerated input in a specific order. Ask the user for 1 distance, then 2 hours, then 3 minutes.

Before you begin codingwrite 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 theremake sure your test for a very longvery 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:
There are 1.61 kilometers in a mile
Python has a builtin round function. You give it a float and itll give you back a float rounded to however many significant digits youve specified. To try it out, open IDLE in interactive mode and try a few things like this:
roundedround5.88888, 3
rounded
You may assume that the user gives you good inputall of the data are nonnegative. The distance is a float and is always greater than zero. Hours and minutes are both whole numbers, and either one may be zero, but the total time is never zero.

AMAZING points: These final two points may be awarded if youve completed the rest of the assignment perfectly and blown us away with
Using a constant variable to store the number of kilometers in a mile.
Using any round or similar functions only for printing out, and do not save any values that have been rounded off.

Example Output

Programming 3
Filename: pi.py

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. Weve all used to calculate the circumference of a circle, because .If the radius of the circle is one, its easy to solve for.

Were going to implement a version of Archimedess 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 reportusing the algorithm described below.

We calculate the perimeter of a polygon using the following algorithm:
Calculate the inner angle shown in the middle figure below. Since there are 360 degrees in a circle, the inner angle is 360 divided by the number of sides in the polygon.
Calculate the half angle shown in the red triangle below, which would be 12 of the inner angle.
Compute the length of the opposite side in the red triangle. Looking back to old, faded trigonometry memories remember SOH CAH TOA?, the sine of an angle is opposite divided by hypotenuse. We know the hypotenuse of the red triangle is 1, and we can calculate the sine of an angle, so solve for the length of the opposite side.
Now that we have the length of the opposite side of the red triangle, double it to get the length of an actual side of the polygon. And now, because all the polygon sides are the same length, you can calculate the polygons perimeter.
Radius1

Polygon inscribing a circle of radius 1
The inner angle is 360n degrees
360n

Radius1

360n
The angle of the red triangle is 360n2 degrees
Radius1

360n2

Helpful hints:
Once you get your angles computed, youll want to convert them to radians or your calculations wont actually get you to .
Youll definitely find Pythons math library useful:
At the top of your .py file, include the line import math
When you need to convert angles into radians, try something like radiansmath.radians36, which would store the value 0.628 in the variable radians
The math library also has a sine function, which you would call with something like sinmath.sin0.628, which would store the value 0.587 in the variable sin
You dont need to write specific test cases for this program, but you should definitely see that, the greater the number of sides you provide, the closer to 3.14159 your calculation gets. Here are a few outputs of my version:

AMAZING points: These final two points may be awarded if youve completed the rest of the assignment perfectly and blown us away with
Really good, descriptive variable names.
Saving intermediate calculations in variables, so that any single line of code isnt trying to do too much.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] algorithm math python DS2000
$25