Write a function called grade that expects one argument

Assignment Help Python Programming
Reference no: EM132356839

Programming Assignment  - Conditionals

Problem 1

Write a function called max4 that expects four arguments, all numbers, and returns the maximum of the four values. Note: you may not use the built-in min or max functions here -- you must provide your own logic for this function. Here are some examples of how your function should work:

>>> max4(1, 2, 3, 4)

4

>>> max4(4.0, 3.9, -1.7, 2)

4.0

>>> max4(-2, -1, -30, -27.2)

-1

>>> max4(7, 7, 7, 7)

7

Problem 2

Write a function called grade that expects one argument, a number representing a score between 0 and 100, and returns a single character as the corresponding letter grade shown in the following table:

Score

Grade

90-100

A

80-89

B

70-79

C

60-69

D

< 60

F

(this problem continues on the next page)

Assume the argument passed to the function is a valid argument; do not validate the argument. Here are some examples of how your function should work:

>>> grade(100) 'A'

>>> grade(0) 'F'

>>> grade(80) 'B'

>>> grade(79.99) 'C'

>>> grade(70) 'C'

>>> grade(65) 'D'

Problem 3

The following rhyme helps us remember how many days there are in any given month: Thirty days has September,

April, June, and November, All the rest have thirty-one,

Except February which has twenty-eight.

More accurate versions of the rhyme deal with the problem posed by the leap year, but let's ignore that for now. Write a function called days which expects one argument, the name of a month as a string, and returns the number of days in that month as given in the rhyme. Assume the argument passed to the function is a valid argument; do not validate the argument. Here are some examples of how your function should work:

>>> days("January") 31

>>> days("February") 28

>>> days("March") 31

>>> days("April") 30

>>>

Problem 4

As you learned from Programming Assignment 2, body mass index is often used in discussions between patients and health professionals about weight-related risk factors. (It should be noted that many health professionals believe that the body mass index isn't all that useful and the labels associated with the numbers are even less useful.)

Using the functions you wrote for Problems 2, 3, and 4 in Programming Assignment 2, now write a new function called bodyMassIndex that expects no parameters, asks the user for information needed to compute a subject's body mass index, then displays the body mass index along with the BMI category obtained from the table below:

BMI < 18.5

underweight

18.5 <= BMI < 25

normal weight

25 <= BMI < 30

overweight

30 <= BMI

obese

Assume the values entered by the user are valid; do not validate the user input. Here are some examples of how your function should work:

>>> bodyMassIndex()

Please enter the subject's name: Eddie

Please enter the subject's height in inches: 70.5 Please enter the subject's weight in pounds: 220 Eddie has a body mass index of: 31.12020146881197 Eddie is obese

>>> bodyMassIndex()

Please enter the subject's name: Albert

Please enter the subject's height in inches: 68 Please enter the subject's weight in pounds: 150 Albert has a body mass index of: 22.80716931676078 Albert is normal weight

When we call your bodyMassIndex function and give the same keyboard input as in the examples above, everything printed by your function should be identical to what you see in the examples above.

Problem 5

Write a function called weekly_pay that expects two arguments, an employee's hourly wage and the number of hours the employee has worked in a week, computes the amount of money to be paid out to the employee for the week, and returns that value as a floating point number. Note that any overtime work (over 40 hours per week) is paid at 150 percent of the regular hourly wage. Assume the arguments passed to the function are valid arguments; do not validate the arguments. Here are some examples of how your function should work:

(this problem continues on the next page)

>>> weekly_pay(10, 40)

400.0

>>> weekly_pay(7.50, 20.5)

153.75

>>> weekly_pay(10, 50)

550.0

>>> weekly_pay(20, 41)

830.0

Problem 6

The following table contains a simplified explanation of how federal income tax is computed in the United States (the numbers are from a previous decade). Different tax rates are applied based on the taxpayer's marital status and total income.

If your status is Single and if

the taxable income is

the tax is

of the amount over

at most $32,000

10%

$0

over $32,000

$3,200 + 25%

$32,000

If your status is Married and

if the taxable income is

the tax is

of the amount over

at most $64,000

10%

$0

over $64,000

$6,400 + 25%

$64,000

Write a function named taxes that computes a taxpayer's income tax. The function expects two arguments. The first argument is either "s" for a single taxpayer or "m" for a married taxpayer. The second argument is a number representing the taxpayer's taxable income. Your function should use the information in the table above to computer the taxes due. Assume the arguments passed to the function are valid arguments; do not validate the arguments. Here are some examples of how your function should work:

>>> taxes("s",

25000)

2500.0

>>> taxes("s",

 

32000)

3200.0

>>> taxes("s",

 

80000.00)

15200.0

>>> taxes("m",

 

50000.00)

5000.0

 

>>> taxes("m",

64000)

6400.0

>>> taxes("m",

 

160000)

30400.0

>>> taxes("s",

 

14700.50)

1470.0500000000002

>>> taxes("m", 172535.38)

33533.845

Reference no: EM132356839

Questions Cloud

Describe major components of agency human resource system : Analyze three to four (3-4) of the major components of the agency's human resource system, processes, and performance evaluation plan for hiring and retaining.
Analyse the implementation of the innovation : 6BDIN002W Innovation & Creativity Assignment, University of Westminster, UK. Analyse the implementation of the innovation
Write a program that request the number of begels ordered : A bagel shop charges 75 cents per begal for orders of less than a half-dozen bagels and 60 cents per begal for orders of a half-dozen or more.
Assessment of the building construction type : It Is recommended that an assessment of the building construction type is conducted to give an accurate assessment of the client's security needs.
Write a function called grade that expects one argument : Write a function called grade that expects one argument, a number representing a score between 0 and 100, and returns a single character.
Demonstrate in-depth knowledge of system engineering : ME503 - Telecommunication System Engineering - Comprehensive analysis of current and emerging PBX systems in terms of reliability
Demonstrate the connection or importance of the article : Summarize each article ensuring that you focus on the relevance of the article to your public health topic. Each summary must clearly demonstrate the connection
What you learned about race and life the given quarter : All essays that talk about what you learned about race and/or life this quarter will get credit for the exam, but essays that do not attempt at least one.
Undermine effective risk management in organization : What are the forces that tend to undermine effective risk management in an organization?

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd