Python CHP 8 Ex Full
Python CHP 8 Ex Full
1
1 A company pays its employee's weekly according to their hourly
wage up to 40 hours and 50% more for the overtime. Write a program
that uses a while statement to receive values of " hourly _ rate " and "
hourly _ worked " for an arbitrary number of employees and finds and
print's the gross pay for each employee.
Input
while True:
# Get input values from user
hourly_rate = float(input("Enter hourly rate (or -1 to quit): "))
The while loop continues until the user enters -1 as the hourly rate.
Inside the loop, the program asks the user for the hourly rate and
hours worked for the employee.
The program then calculates the gross pay for the employee using the
formula provided: regular pay for up to 40 hours plus 50% more for
any hours over 40.
The round() function is used to round the gross pay to 2 decimal places.
Finally, the program prints the gross pay for the employee.
You can run this program in a Python environment or save it as a .py
file and run it from the command line.
5.3
Input
while True:
# Get input values from user
fixed_pay = float(input("Enter fixed pay (or -1 to quit): "))
The while loop continues until the user enters -1 as the fixed pay.
Inside the loop, the program asks the user for the fixed pay and
gross sales for the salesperson.
The program then calculates the gross pay for the salesperson using
the formula provided: fixed pay plus 9% of gross sales.
The round() function is used to round the gross pay to 2 decimal
places.
Finally, the program prints the gross pay for the salesperson.
You can run this program in a Python environment or save it as a
.py file and run it from the command line.
5.6
write a program for the secant method for solving the non linear
equation: f(x) = 4x + sinx-e'x with intial two roots x not =0 and x1= 1 .
The iterations of the method should stop/ terminate when a certain
tolerance/ convergence level is achieved or maximum number of
iterations are performed (whichever happens first)
Input
import math
5.5
write a program for the Newton's method for solving the non linear
equation: f(x) = 4x+sinx-e'x=0 with initial root x not = 1 the iterations
of the method should stop / terminate when a certain tolerance/
convergence level is achieved or a maximum number of iterations are
performed ( whichever happens first )
Input
import math
Input
import math
Input
# Define a while loop to ask for units consumed for each customer
while True:
# Ask the user for input
units = input("Enter the number of units consumed (or 'q' to
quit): ")