Problem Solving Saturday
Problem Solving Saturday
@GlobalEdx
Program
num = int(input())
if num % 2 != 0:
print( "Weird")
else:
if num >= 2 and num <= 5:
print ("Not Weird")
elif num >= 6 and num <= 20:
print ("Weird")
elif num > 20:
print ("Not Weird")
Program
num = int(input())
i=0
while i<num:
print(i**2)
i=i+1
Chris owns an auto repair business and has several employees. If any employee works over
40 hours in a week, he pays them 1.5 times their regular hourly pay rate for all hours over
40. He has asked you to design a simple payroll program that calculates an employee’s
gross pay, including any overtime wages. You design the following algorithm:
Get the number of hours worked.
Get the hourly pay rate.
If the employee worked more than 40 hours:
Calculate and display the gross pay with overtime.
Else:
Calculate and display the gross pay as usual.
Program Output
Enter the number of hours worked: 40
Enter the hourly pay rate: 20
The gross pay is $800
Program Output
Enter the number of hours worked: 50
Enter the hourly pay rate: 20
The gross pay is $1100
BASE_HOURS = 40 # Base hours per week
OT_MULTIPLIER = 1.5 # Overtime multiplier
if hours_worked>BASE_HOURS:
overtime_hours = hours_worked - BASE_HOURS
overtime_pay = overtime_hours * pay_rate * OT_MULTIPLIER
gross_pay = BASE_HOURS * pay_rate + overtime_pay
print('The gross pay is $', gross_pay)
else:
gross_pay = hours_worked * pay_rate
print('The gross pay is $', gross_pay)
user_number = int(input('Enter a number between 1 and 10: '))
if user_number < 1 or user_number > 10:
message = "\nError. Number must be between 1 and 10."
else:
if user_number == 1:
print('I')
elif user_number == 2:
print('II')
elif user_number == 3:
print('III'
elif user_number == 4:
print('IV')
elif user_number == 5:
print('V')
elif user_number == 6:
print('VI')
elif user_number == 7:
print('VII')
elif user_number == 8:
print('VIII')
elif user_number == 9:
print('IX')
elif user_number == 10:
print('X')
Your friend Amanda just inherited a European sports car from her uncle. Amanda lives
in the United States, and she is afraid she will get a speeding ticket because the car’s
speedometer indicates kilometers per hour (KPH). She has asked you to write a
program that displays a table of speeds in KPH with their values converted to miles per
hour (MPH). The formula
for converting KPH to MPH is: MPH KPH * 0.6214
In the formula, MPH is the speed in miles per hour and KPH is the speed in kilometers
per hour. The table that your program displays should show speeds from 60 KPH
through 130 KPH, in increments of 10, along with their values converted to MPH. The
table should look something like this:
START = 60
END = 131
INCREMENT = 10
CONVERSION_FACTOR = 0.6214
print('KPH\tMPH')
print('--------------')
while START<=END:
mph = START * CONVERSION_FACTOR
print(START,'\t', mph)
START+=INCREMENT