Practice #7 The Program – Payroll Program with Input Validation A variation of Programming Exercise # 1 page 349. Please be sure to read these instructions. Design a payroll program that prompts the...

1 answer below »
The instructions are in all 3 different files.


Practice #7 The Program – Payroll Program with Input Validation A variation of Programming Exercise # 1 page 349. Please be sure to read these instructions. Design a payroll program that prompts the user to enter an employee’s hourly pay rate and the number of hours worked. Validate the user’s input so that only pay rates in the range of $7.50 through $18.25 and hours in the range of 0 through 40 are accepted. The program should display the employee’s gross pay. For this assignment you can assume that the user will enter a valid floating point numbers. You do not need to handle the case when the user enters a non-numeric value. Use GLOBAL CONSTANTS for the minimum and maximum hourly rates, as well as the maximum number of hours worked in a week. Modularize your program by creating two functions using the following function headers: def get_hours(): def get_rate(): Remember, these are functions (chapter 6), not procedures (chapter 3). The both must return a value. Screenshot Here's an example of what you program should look like. What To Turn In For this assignment you need to turn in: · Your working Python program file named Practice_07.py. Notes and Comments · You may help each other on these practice assignments, but not on the homework assignments. See the syllabus for details. I will also be available in class if you need assistance. · All of your assignments must follow the coding standards we discussed in class. · I suggest your check your program against the check list before you turn it in. · Be sure to turn in your assignment via the Blackboard site before then end of class tonight for full credit. Homework #7 The Pseudocode – Input Validation There is no pseudocode assignment for this week due to final exam next week. Please be mindful of pseudocode from this chapter for input validation. Pseudocode will return with chapter 8. The Program – Fat Gram Calculator A variation of Programming Exercise # 3 page 349. Please be sure to read these instructions. Write a program to calculate the percentage of fat calories in a food item. Your program should allow the total number of calories in the food item and the number of grams of fat. Validate the input as follows: · Make sure the number of calories and the number of fat grams are not less than 0. · There are 9 calories in every gram of fat. The calories from fat must not exceed the total calories in the food item. Make sure that the number of calories entered is not greater than fat grams times 9. Tell the user if the item is a low fat food item. A low fat food gets 30% or less of its calories from fat. Screenshot Here's an example of what you program should look like: Suggestions In this assignment you will be checking for reasonableness. You will not be checking for data type mismatch. This is similar in nature to what we did in Program_07_02.py. You do not need a boolean variable in this assignment, like the one we used in Program_07_02b.py. There are several ways to write your loop for defensive programming. I suggest you stick to the author's method used in Program_07_02.py . That was a priming read followed by a while loop. I won't take off points if you do it another way, but this ways is just as easy as the others. Formatting Please note: I’ve been taking off up to 6 points for indentation and spacing mistakes. This is a full letter grade(s) for the assignment. I will take off one point each indentation mistake, up to a maximum of three points. Same for comments, one point for each line error, up to a maximum of three points. Reminder one blank line prior to any comment and two blank lines before a module / procedure / function. Please don’t let these easy fixes happen to you. What To Turn In For this assignment you need to turn in: · Your working Python program file named Homework_07.py. · Screenshot of completed shell or pasted in Word file as HomeworkShell_07.doc or saved completed shell as HomeworkShell_07.py. Homework #12 The Program Part A.The Pseudocode and A - Write pseudocode for what you create below using Chapter 1-7, & 12 methods. 15 points Review instructions below. They are like a variation and combination of programming exercises #1, 2, 3, and 4 of the text book page 620-621 5th edition. Part BPython the Program: B - Write a python program using Chapter 1- 7, & 12 methods. 15 points Below is a variation and combination of the books exercises #1, 2, 3, and 4 of the textbook page 620-621 5th edition. You can read those but please be sure to follow the directions below: Write a program that prompts the user to enter a string. Your program should then: · Display the number of vowels in the string, not counting Y (treat Y as a consonant). · Display the string with the first letter of each word capitalized, and the rest of the string in lower case. · Sum of all the digits in the string (e.g. Hello 123! would be six). · Display the string backwards. Use only the functions that we learned in class. Do not use new library functions for this. This includes, but not limited to: · Regular Expressions · replaceAll() or any other replace function/procedure · split() · reverse() or any other reverse function/procedure Allow the users to keep entering strings until they enter an empty string. Be sure to display all appropriate messages and prompts. Screenshot Here's an example of what you program should look like: Notes · This assignment can be correctly done with either one, two, or four loops. · Whether you use one, two, or four loops in your program, you should have two string variables and two integer variables for your output, one output variable for each of the bullet points listed. · Your loops should look at the characters in the input string one character at a time, just like the loops we did in the demo programs this week. · Make sure your program still works correctly if they user enters more than one string. · Make sure you follow the coding standards for this class, even if the author does not. Run through Pep8. What To Turn In For this assignment you need to turn in: · Your pseudocode file named Homework_12.doc, .pdf, or .txt. · Your working Python program file named Homework_12.py. · Screenshot of completed shell or pasted in Word file as HomeworkShell_12.doc or saved completed shell as HomeworkShell_12.py.
Answered Same DayMar 21, 2021

Answer To: Practice #7 The Program – Payroll Program with Input Validation A variation of Programming Exercise...

Abhishek answered on Mar 22 2021
149 Votes
37735 - Programming in Python/Screen shots/Homework_12.png
37735 - Programming in Python/Screen shots/Homework_07.png
37735 - Programming in Python/Screen shots/Practice_07.png
37735 - Programming in Python/Solution/Homework_12.py
# Homework_12.py
# Program to perform various operations on a string
# main function to test the program
def main():
# i
nfinite loop to take multiple strings
while True:
inputString = input("Please enter some text or press to exit:\n")
if inputString == "":
exit(0)
vowels = 0
capitalized = ""
sumOfDigits = 0
backward = ""

# previous character
prev=' '
for c in inputString:
# current character in lower case
temp = c.lower()
# current caharcter is a vowel
if temp=='a' or temp =='e' or temp =='i' or temp =='o' or temp =='u':
vowels = vowels + 1
# previous character was a space, this will be capital
if prev == " ":
capitalized = capitalized + c.upper()
else:
capitalized = capitalized + temp
# this is a digit add it to the sum of digits
if c.isdigit():
sumOfDigits = sumOfDigits + int(c)
# add the current character to beginning of backward string
backward = c + backward
# set current character as previous character
prev = c
# print the result
print("\nVowels: "+str(vowels))
print("Capitalized: "+capitalized)
print("Sum of digits: "+str(sumOfDigits))
print("Backwards: "+backward)
print("")
if __name__ == "__main__": main()
37735 - Programming in Python/Solution/Homework_07.py
# Homework_07.py
# Program to calculate the percentage of fat calories in a food item
# get the calories in the food item
def getCalories():
calories = int(input("How many calories per serving? "))
# number of calories is less than 0
if calories < 0:
print("Number of calories must not be negative.")
return getCalories()
return calories
# get the number of fatGrams when calories are passed
def getFat(calories):
fat = int(input("How many grams of fat? "))
fatCalories = fat * 9
# number of fat is less than 0 or calories in fat is more than total calories
if fat < 0 or fatCalories > calories:
print("Number of grams of fat must not be negative and calories from fat cannot exceed the total calories.")
return getFat(calories)
return fat
# main function to test the program
def main():
calories = getCalories()
print("")
fat=getFat(calories)
print("")
fatCalories = (fat * 9)/calories * 100
# if fatCalories is less than 30
# it is a low fat food
if fatCalories < 30:
print(str(fatCalories)+"% of calories from fat. This is a low fat food.")
else:
print(str(fatCalories)+"% of calories from fat.")
if __name__ == "__main__": main()
37735 - Programming in Python/Solution/Practice_07.py
# constants for thsi program
MINIMUM_HOURS = 0
MAXIMUM_HOURS = 40
MINIMUM_RATE = 7.50
MAXIMUM_RATE = 18.25
#get and return valid number of hours worked between 0-40
def get_hours():
hours = int(input("Enter the number of hours worked: "))
# check that the hours are in valid range
if hours < MINIMUM_HOURS or hours > MAXIMUM_HOURS:
print("ERROR - Invalid number of hours!")
return get_hours()
return hours
#get and...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here