Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 A) Write a program sign.py to ask the user for a number. Print out which category the number is in: 'positive', 'negative', or

Python 3 A) Write a program sign.py to ask the user for a number. Print out which category the number is in: 'positive', 'negative', or 'zero'.

B) In Idle, load grade1.py and save it as grade2.py Modify grade2.py so it has an equivalent version of the letterGrade function that tests in the opposite order, first for F, then D, C, .... Hint: How many tests do you need to do? [3] Be sure to run your new version and test with different inputs that test all the different paths through the program. grade1.py code:

'''Test if-elif-...-else determining a letter grade.'''

def letterGrade(score): if score >= 90: letter = 'A' elif score >= 80: letter = 'B' elif score >= 70: letter = 'C' elif score >= 60: letter = 'D' else: letter = 'F' return letter

def main(): x = float(input('Enter a numerical grade: ')) letter = letterGrade(x) print('Your grade is ' + letter + '.')

main()

C) Modify the wages.py or the wages1.py example to create a program wages2.py that assumes people are paid double time for hours over 60. Hence they get paid for at most 20 hours overtime at 1.5 times the normal rate. For example, a person working 65 hours with a regular wage of $10 per hour would work at $10 per hour for 40 hours, at 1.5 * $10 for 20 hours of overtime, and 2 * $10 for 5 hours of double time, for a total of 10*40 + 1.5*10*20 + 2*10*5 = $800. You may find wages1.py easier to adapt than wages.py. Wages1 Code:

'''if-else example: calculate weekly wages -- alternate version'''

def calcWeeklyWages(totalHours, hourlyWage): #NEW '''Return the total weekly wages for a worker working totalHours, with a given regular hourlyWage. Include overtime for hours over 40. ''' if totalHours <= 40: regularHours = totalHours overtime = 0 else: overtime = totalHours - 40 regularHours = 40 return hourlyWage*regularHours + (1.5*hourlyWage)*overtime

def main(): hours = float(input('Enter hours worked: ')) wage = float(input('Enter dollars paid per hour: ')) total = calcWeeklyWages(hours, wage) print('Wages for {hours} hours at ${wage:.2f} per hour are ${total:.2f}.' .format(**locals()))

main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago