Computer science project

profileJerry Shen
Project1.zip

Project1/convert_age.py

Age_on_Earth=float(input('Enter your age on Earth: ')) days=[365.25,87.97,687,4331.87,10760.27,60189.55] planet=int(input('Select a planet:1 for Merccury, 2 for Mars, 3 for Jupiter, 4 for Saturn, 5 for Neptune: ')) Age_on_planet=(365.25/days[planet])*Age_on_Earth Types_of_planet=['Earth','Merccury','Mars','Jupiter','Saturn','Neptune'] print('Your age on ', Types_of_planet[planet] , 'is ',Age_on_planet,' years')

Project1/convert_age_2.py

Home_planet=int(input('Select your home planet: 1 for Mercury, 2 for Mars, 3 for Jupiter, 4 for Saturn, 5 for Neptune: ')) Age_on_home_planet=float(input('Enter your age on your home planet: ')) Destination=int(input('Select your destinaion planet: 1 for Mercury, 2 for Mars, 3 for Jupiter, 4 for Saturn, 5 for Neptune: ')) planet=[365,87.97,687,4331.87,10760.27,60189.55] planets=['Earth','Mercury','Mars','Jupiter','Saturn','Neptune'] Age=(planet[Home_planet]/planet[Destination])*Age_on_home_planet print('Your age on',str(planets[Destination]),'is',Age,'years')

Project1/Earth_to_Mars.py

Earth_years = float(input('Enter the number of Earth years: ')) Earth_TO_Mars = 365/687 value = Earth_years*Earth_TO_Mars print('This is',value,'years on Mars')

Project1/overdue_tax.py

PENALTY_RATE = 0.06 #Do not change EARTH_YEAR = 365 #Do not change tax = input('Enter amount of tax owed: ') #Do not change, will be in format $100 rate = input('Enter interest rate: ') #Do not change, will be in format 4% late = int(input('Enter number of days overdue tax is: ')) #Do not change, will be an integer penalty = PENALTY_RATE * float(tax[1:]) interest = (float(rate[:-1])/100)*(late/EARTH_YEAR)*float(tax[1:]) total = float(tax[1:])+penalty+interest print('Your total payment is' , total)

Project1/Project1_v9.pdf

CSCI 140 Programming for Data Science Project 1 Due Friday, 13 September 2019 at 1700

Checkpoint Deadline: Tuesday, 10 September 2019 at 1700

In our first project, your task is to create 2 short programs, complete one program, and correct a fourth program. There are four programs to submit, each performing one task. They can all be completed using only the material introduced in the first couple of days of class. You will submit these are separate files with the extension .py, but you can write and test your programs in a notebook if you prefer. In the problem solving session, you will practice creating, saving, and running .py files.

We suggest that for each program you write an algorithm as a simple numbered list of steps and then create a Python implementation. Your submission will consist of a PDF document containing your reflections on the project, and four Python programs saved in .py files named as specified.

Program One: Convert Earth Years to Mars Years

Elon Musk plans to retire on Mars. One year on Mars is 687 Earth days. One year on Earth is 365.25 Earth days. So, for example, if he stays on Mars for 16 Mars years, that’s about 30 Earth years.

Write a program that solicits a single input from the user: a number of Earth years. Your program should convert the Earth years to Mars years using the information given above.

You must format the program's interaction as illustrated in the following examples. Do not vary the phrasing, capitalization, spacing, etc. You must also write a properly styled, easily readable and understandable program.

Enter number of Earth years: 10 This is 5.316593886462882 years on Mars. Enter number of Earth years: 0.5 This is 0.26582969432314413 years on Mars.

Your program must be called Earth_to_Mars.py and should work for any non-negative numeric input provided by the user. Other inputs will not be tested.

Program Two: Calculate Retirement Contributions

Speaking of retirement, you need to start saving early if you’re going to make it to Mars. Many employers offer workplace retirement accounts. Money is deducted (taken out) of an individual’s salary and is put into a separate account that is not accessible (usually) until retirement. Individuals get to select the amount they want to save per paycheck.

Suppose that an individual wants to try to have the same amount deducted from every paycheck to hit a target for retirement savings. Many workplaces only allow you to deduct money for retirement as full dollar amounts, that is $50 as opposed to $50.50. This means that the last payment for the year will have to include a few extra dollars to hit their savings target.

Here are some examples of the calculations – this is not code and is not what your program’s output should look like.

Example 1:

Target is $10000 and individual is paid 12 times per year

They save $833 dollars from the first 11 paychecks, which gives a total of $9163, so they need to save an extra $4 in the last paycheck, for a total of $837, to reach the target of $10000.

(You might be wondering, why not just save $834 each paycheck? The goal is not to overshoot the target, because if you overshoot the IRS limit, you’ll find yourself in a lot of trouble.)

Example 2:

Target is $3600 and individual is paid 24 times per year

In this case, they can save $150 from each paycheck and meet the target exactly. There is no extra money to deduct from the last paycheck.

Write a program that calculates the amount of each equal deduction per paycheck, and how many extra dollars should be added to the last payment to hit the target. Your program will solicit two inputs from the user: a target amount in whole dollars (no cents) and the number of times an individual is paid per year. Save this program in a file called retirement.py.

Program execution should look like what is shown below. Pay special attention to formatting, spacing, and capitalization of the input and output lines. Enter total amount to save: 10000 Enter number of paychecks per year: 12 You must make 11 deductions of $833 and one final deduction of $837 to save $10000 Enter total amount to save: 3600 Enter number of paychecks per year: 24 You must make 23 deductions of $150 and one final deduction of $150 to save $3600

Note that the output is the same whether or not the final payment is a different value. You can assume that the inputs for the target and number of paychecks will be positive integers, and your program should work for any such inputs.

Program Three: Fountain of Youth

In Program 1, you converted from years on Earth to years on Mars. We now want to consider other planets, and figure out what your age would be on other planets, using their definition of a year. For our purposes, a ‘year’ is the time it takes for a particular planet to orbit the sun (a revolution). The table below shows how long a year lasts on other planets in terms of Earth days:

Mercury 87.97 Earth days

Mars 687 Earth days

Jupiter 4331.87 Earth days

Saturn 10760.27 Earth days

Neptune 60189.55 Earth days

Write a program to convert your age in Earth years to your age in years on any of these 5 planets. You have been given three lines of code that you cannot change in any way which must be used for your program in the file convert_age.py. The program will take two inputs: an age in Earth years and a number indicating which planet to use for the conversion.

Program execution should look like what is shown below. Pay special attention to formatting, spacing, and capitalization of the input and output lines. Enter your age on Earth: 80 Select a planet: 1 for Mercury, 2 for Mars, 3 for Jupiter, 4 for Saturn, 5 for Neptune: 2 Your age on Mars is 42.53275109170306 years Enter your age on Earth: 12.5 Select a planet: 1 for Mercury, 2 for Mars, 3 for Jupiter, 4 for Saturn, 5 for Neptune: 1 Your age on Mercury is 51.89979538479027 years

You can assume that the inputs for age will always be positive numbers, but they may have fractional components. You can also assume that the inputs for selecting a planet will always be one of the integers 1,2,3,4, or 5. No other inputs will be tested.

N.B.: you must only use programming structures discussed so far – this means no conditionals and no imported mathematical functions/modules and no object types that we have not discussed yet. You don’t need them here.

Program Four: The Taxman

If you fail to pay income tax in a timely manner and you owe the government (or the state you live in) money, you are subject both to a penalty and interest on the amount owed. Even if you are living on Mars, if you are a US citizen, you have to file Federal taxes.

Suppose that during your stay-cation on Mars, the interstellar mail took too long and you haven’t paid your taxes on time . . . your tax return was literally lost in space. You owe the original tax plus a penalty that is 6% of the tax amount – for our purposes the penalty will always be 6%. You also owe interest on the tax (not the penalty, just the tax). The amount of interest depends on the current yearly rate and the amount of interest you owe depends on how many days overdue the tax is. This is best shown by a few examples.

Example 1:

Tax owed: $500, 365 days (1 year) overdue

Penalty (6% of tax owed): $30

Interest rate: 5% yearly

Interest owed (5% of tax owed): $25

Total amount to pay: $555

Example 2:

Tax owed: $500, 1095 days (3 years) overdue

Penalty (6% of tax owed): $30

Interest rate: 4% yearly

Interest owed (4% of tax owed per year times 3 years): $60

Total amount to pay: $590

Example 3:

Tax owed: $500, 250 days overdue

Penalty (6% of tax owed): $30

Interest rate: 4% yearly

Interest owed (4% of tax owed per year times 250 days out of 365): approx.. $13.70

Total amount to pay: $543.70

In the file overdue_tax.py, you have been code for a program that provides constants for the length of a year and the penalty rate, and solicits the tax owed, the number of days overdue, and the interest rate from the user. The program is supposed to calculate the total amount owed, but the program is incorrect. Your job is to debug the program. Debugging the code means that you edit the lines in place. You should not add lines, delete lines, or move the order of lines. Correct the lines as they are and preserve as much of the original code as possible. HINT: figure out what each line is trying to accomplish first before making any changes.

The user (and our testing program) will enter the data in the following formats: tax owed will be a string that starts with a dollar sign, e.g., $10000 and interest rate will be a string that is a percentage with a percent sign, e.g. 5%. The days overdue will be entered as an integer.

Here are some examples of program execution. Pay special attention to the formats of the inputs and outputs – your printed output should match exactly in terms of spacing and text, but your output may have slightly different numbers of decimal places or differences in the decimal portion and that is OK (e.g. 543.6986301369863 versus 543.6986301369864):

Enter amount of tax owed: $500 Enter interest rate: 5% Enter number of days overdue tax is: 365 Your total payment is 555.0 Enter amount of tax owed: $500 Enter interest rate: 4% Enter number of days overdue tax is: 1095 Your total payment is 590.0 Enter amount of tax owed: $500 Enter interest rate: 4% Enter number of days overdue tax is: 250 Your total payment is 543.6986301369863

Your program should work for any inputs in the format shown – inputs representing numeric values will always be positive numbers, but keep in mind that tax owed may not be in exact dollar values (i.e. there may be cents like $15000.25 – the IRS usually rounds to the nearest dollar but we won’t) and the interest percentage may not be a whole number and may have more than a single digit (e.g. 10.5%). The number of days will always be input as a positive integer.

N.B.: you must only use programming structures discussed so far – this means no conditionals and no imported mathematical functions/modules and no object types that we have not discussed yet. You don’t need them.

Extra credit opportunities:

Please note that the following tasks are worth a small percentage of extra credit (up to 3%).

1) Program 4 produces outputs that are dollar amounts that may include cents. Format the output so that it prints with two decimal places exactly. It is find to round the second decimal place based on the value of the third decimal place. You may import any modules and use any functions you like to accomplish this. Save this program in a separate file with the name overdue_tax_2.py

2) Write a modified version of Program 3 that allows the user to input their age on a home planet and then converts their age to the selected destination planet. The program will provide the output in the requested format. You must implement this WITHOUT using conditionals. Save this as convert_age_2.py. Here is an of how this should work. This example doesn’t include Earth as an option, but you can include it if you like.

Select your home planet: 1 for Mercury, 2 for Mars, 3 for Jupiter, 4 for Saturn, 5 for Neptune: 1 Enter your age on your home planet: 10 Select a destination planet: 1 for Mercury, 2 for Mars, 3 for Jupiter, 4 for Saturn, 5 for Neptune:2 Your age on Mars is 1.280494905385735 years

SUBMISSION EXPECTATIONS

Project1.pdf A PDF document containing your reflections on the project, and information on any extra credit opportunities you pursued. You must also cite any sources you use. Please be aware that you can consult sources, but all code written must be your own. Programs copied in part or wholesale from the web or other sources will receive 0 points and will result in reporting of an Honor Code violation.

Earth_to_Mars.py Your implementation of program one, following the format specified above.

retirement.py Your implementation of program two, following the format specified above.

convert_age.py Your completed implementation of program three.

overdue_tax.py Your corrected implementation of program four.

Any programs you attempted for extra credit as separate files.

Checkpoint submission

You may submit any and all parts of the project by Tuesday September 10 to receive feedback from our automated testing script. This is automated feedback only but will show you if your programs have failed any of our test cases. Please be aware that you will receive no feedback if your files are incorrectly named or are in an incorrect format.

SUGGESTED COMPLETION SCHEDULE

Each project will offer you a suggest completion schedule to help you manage your time. Working incrementally is essential to learning the material, minimizing frustration, and finishing projects by the deadline. This schedule is based on when topics are presented in lecture. This will put you on track to have versions of 3 of the 4 programs to submit by the checkpoint deadline.

Earth_to_Mars.py: Complete after lecture 9/2 or 9/3

retirement.py: Start after lecture 9/2 or 9/3, Complete after lecture 9/4 or 9/5

convert_age.py: Complete after lecture 9/9 or 9/10

overdue_tax.py: Complete after lecture 9/4 or 9/5

POINT VALUES AND GRADING RUBRIC

Program 1: 15 points

Program 2: 27.5 points

Program 3: 27.5 points

Program 4: 27.5 points

Write-up: 2.5 points

The general grading rubric for projects is below. Some of the specifics given in the rubric are not applicable to this project (e.g. import lines and copious commenting).

Project1/retirement.py

amount_to_save = int(input('Enter total amount to save: ')) paychecks = int(input('Enter number of paychecks per year: ')) deduction_times = int(paychecks -1) deduction = amount_to_save//paychecks final_deduction = amount_to_save - deduction_times*deduction print('You must make '+str(deduction_times)+' deductions of $'+str(deduction)+' and one final deduction of $'+str(final_deduction)+' to save $'+str(amount_to_save))

Project1/Write up.doc

Project1/Write up.pdf

CS140 Professor Willner

Wenda Shen In this project, I finished the reading assignment and reviewed the class notes, so

that I can attempt the project by using the knowledge we already learned. So far I

didn’t look for anything on internet in order to finish the project. This project helps

me learn how to differentiate int, float, and strings, and how to refer to a certain

position in a list. Moreover, I also learned how to use the correct format to avoid

error.