关键词 > Python代写

Assignment 2

发布时间:2021-09-23

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Assignment 2


INSTRUCTIONS

Overview. For this assignment you will be writing 3 programs which should be saved independently as their own ".py" file. When you're finished you should submit your programs to the Assignment #1 category in Brightspace.


File Naming. Your solution to the first problem should be named as follows:

LastNameFirstName_Assign2_Problem1.py

# Example: LiaoSusan_Assign2_Problem1.py

# Change the integer after the problem for each problem


File Instructions. At the top of your assignment, please include your name, the assignment number, the problem number, the date, and the name of your program at the top of your file as comments. If you worked with another student, you should also include their name. It should look like this:

"""

Name: Susan Liao

Assignment: 2

Problem: 1

Date: 2021-09-21

Program Name: LiaoSusan_Assign2_Problem1.py

Partner: Ada Lovelace

"""


Each problem will give detailed instructions on how data should be stored and manipulated. Also comment your source code and describe your code to someone who may be viewing it for the first time.


Groupwork. You may work by yourself or with a partner. If you choose to work with someone else please be sure to give them credit in your source code and on NYU Brightspace when you submit your work. Each member of a team must submit their own copy of the assignment to get credit for the assignment.


PROBLEM 1: Mathematical Operations and the print() Function (3 points)

You and your friends just won the lottery. Now you need to figure out how much money everyone is entitled to. To do this you will be writing a short program that prompts the user for the amount they won, the number of people who are splitting the winnings, and the tax rate that will be applied to each person's share. Your program should then figure out how much each person will earn after taxes are applied to each share.


INPUT: Your program accepts the total amount won, the number of people who are splitting the winnings, and the tax rate (as an integer - i.e. 35 = 35%). Ensure that you store your data using variables of the appropriate data type.


OUTPUT: Compute the total amount won, the amount of each share, the tax due on each share and the final take-home amount for each person. Ensure that each of these values is formatted to two decimal places, and that the "comma" separator is included in your currency values, if necessary.


Here are two sample input/output examples. User input is underlined:

Example 1:

How much money did you win? 1000000

How many people are splitting the winnings? 4

What is the percent tax rate on lottery winnings? 25


As a group, you’ve won $1000000.00! Congratulations!

Split 4 ways that amounts to $250000.00 in winnings per person.

Since the tax rate is 25 percent, each person must pay $62500.00 in taxes.

Each person will take home $187500.00 after taxes.


Example 2:

How much money did you win? 5000000

How many people are splitting the winnings? 5

What is the percent tax rate on lottery winnings? 10


As a group, you’ve won $5000000.00! Congratulations!

Split 5 ways that amounts to $1000000.00 in winnings per person.

Since the tax rate is 10 percent, each person must pay $100000.00 in taxes.

Each person will take home $900000.00 after taxes.


PROBLEM 2: Nested Selection Statements (7 points)

For this assignment you will be writing a "diagnostic" program that will be able to tell a user what day of the week it is from September 01, 2021 to November 30, 2021. The program should begin by asking the user to supply a month and a date in integer values. Then, it will print the day of the week it is. Assume that the user makes no errors in data entry.


Here are a few sample runnings of the program. Underlined text indicates user input:

Example 1:

Enter the month: 9

Enter the date: 21


9-21-2021 is a Tuesday.


Example 2:

Enter the month: 10

Enter the date: 8


10-8-2021 is a Tuesday.


Example 3:

Enter the month: 11

Enter the date: 1


11-1-2021 is a Monday.


EXTRA CREDIT: Generating Error Messages (0.5 points)

Sometimes users do not follow instructions when entering data. For example, 13 is an invalid month because there is no 13th month and 8 is an invalid month because it falls outside the designated range. For extra credit, add two lines of code to the beginning of your solution to Problem 2 that will print an error message if the user enters in an incorrect month. The first line should include a Boolean short-circuit evaluation. The second line should print the statement “That’s an invalid month.”.


Here are a few sample runnings of the program. Underlined text indicates user input:

Example 1:

Enter the month: 8

Enter the date: 21


That’s an invalid month.


Example 2:

Enter the month: 0

Enter the date: 15


That’s an invalid month.


If you decide to submit this problem for extra credit, please name it as follows:

Example: LiaoSusan_Assign2_Extra.py


* Note: you can assume the user will always enter in an integer value.

* Hint: recall the two types of short-circuit evaluation covered in Module 3.

* Note: for this extra credit problem, we are only focusing on the month entry error, but other types of data entry errors exist. For example, entering in 9 for the month and 31 for the date should also generate an error because September only has 30 days.