Need help with my python code " # Prompt the user for hours and rate per hour hours = float(input("Enter Hours: ")) rate = float(input("Enter Rate: ")) # Calculate errors in program if hours <= 40 or rate <0: print("Error: It's not a valid input. You can only enter positive numbers.") continue if numbers are not entered print ("Error: It's not a valid input. You can only enter numbers.") break return hours, rate def compute_pay(hours, rate): """docstring for compute_pay""" if hours <= 40: pay = hours * rate else: #1.5 times the hourly rate for hours worked above 40 hours regular_hours = 40 overtime_hours = hours - regular_hours pay = (regular_hours * rate) + (overtime_hours * 1.5 * rate) return Pay # Display the calculated pay def print_output(Pay): print("Pay:", pay)" Here's the python problem: " Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay which takes two parameters ( hours and rate). Enter Hours: 50 Enter Rate: 10 Pay: 575.0 YOU NEED THREE FUNCTIONS: get_input => returns 2 values the rate and the hours => validate the inputs compute_pay => gets the 2 values the rate and the hours and will return the pay print_output=> gets the pay and will print it Call the functions and passing the arguments in the "main" function. Example: def main(): the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) if __name__ == "__main__: main()"
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Need help with my python code "
# Prompt the user for hours and rate per hour
hours = float(input("Enter Hours: "))
rate = float(input("Enter Rate: "))
# Calculate errors in program
if hours <= 40 or rate <0:
print("Error: It's not a valid input. You can only enter positive numbers.")
continue
if numbers are not entered
print ("Error: It's not a valid input. You can only enter numbers.")
break
return hours, rate
def compute_pay(hours, rate):
"""docstring for compute_pay"""
if hours <= 40:
pay = hours * rate
else:
#1.5 times the hourly rate for hours worked above 40 hours
regular_hours = 40
overtime_hours = hours - regular_hours
pay = (regular_hours * rate) + (overtime_hours * 1.5 * rate)
return Pay
# Display the calculated pay
def print_output(Pay):
print("Pay:", pay)"
Here's the python problem: "
Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay which takes two parameters ( hours and rate).
Enter Hours: 50
Enter Rate: 10
Pay: 575.0
- YOU NEED THREE FUNCTIONS:
- get_input => returns 2 values the rate and the hours => validate the inputs
- compute_pay => gets the 2 values the rate and the hours and will return the pay
- print_output=> gets the pay and will print it
Call the functions and passing the arguments in the "main" function.
Example:
def main():
the_hours, the_rate = get_input()
the_pay = compute_pay(the_hours, the_rate)
print_output(the_pay)
if __name__ == "__main__:
main()"
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images