代写C代码 代做C程序 C辅导 C家教

远程写代码 Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

这是一门Python编程基础课,可以提供相关代码的代写和辅导。

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)

  • 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

 

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

  • Filename: currency.py

 

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

  • 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 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:

  1. Miles the runner ran, converted from kilometers. Round to two significant digits.
  2. Average pace per mile, in minutes and seconds.
  3. 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:

  1. Number of kilometers they ran, a float
  2. Number of hours, a whole number
  3. Number of minutes, a whole number

 

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:

  • There are 1.61 kilometers in a mile
  • Python has a built-in round function. You give it a float and it’ll give you back a float rounded to however many significant digits you’ve specified. To try it out, open IDLE in interactive mode and try a few things like this:

>>> rounded = round(5.88888, 3)

>>> rounded

  • You may assume that the user gives you “good” input -- all of the data are non-negative. 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 you’ve 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  . 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:

  1. 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.
  2. Calculate the half angle (shown in the red triangle below), which would be 1/2 of the inner angle.
  3. 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.
  4. 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 polygon’s perimeter.

 

Helpful hints:

  • Once you get your angles computed, you’ll want to convert them to radians or your calculations won’t actually get you to .
  • You’ll definitely find Python’s 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 radians = math.radians(36), 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 sin = math.sin(0.628), which would store the value 0.587 in the variable sin
  • You don’t 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 you’ve 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 isn’t trying to do too much.

相关推荐