In: Computer Science
**Use Python 3.7.4 ***
1. Ask the user for the number of hours worked, salary per hour and compute their salary. They will make 1.5 times salary for every hour over 40.
2. Write a program that asks the user for red, green, and blue color mixture (3 inputs); all or nothing - you can decide how to do this (0/1), (0/255), (none/all), (...). Then based on the combination display the final color: (white - 111, red - 100, green - 010, blue - 001, cyan - 011, magenta - 101, yellow - 110, black - 000)
3. Write a program and asks user for a phone number with area code. Must be formatted like this, " (###)-###-#### " the program should say whether or not it is in the valid format.
#------- wage_cal.py ---------
#version python 3.7.4
def calc_wage(hours,hourPay):
if(hours<=0 or hourPay<=0):
return 0
if(hours<=40):
return hours*hourPay
else:
overtime = hours-40
overtime_pay = overtime * 1.5 *hourPay
main_pay = 40 * hourPay
total_pay = overtime_pay + main_pay
return total_pay
for i in range(3):
print("\nWage Calculation Test:",i+1)
try:
hours = int(input("Enter No.of Hours worked : ").strip())
hourPay = float(input("Enter Pay per Hour : ").strip())
wage = calc_wage(hours,hourPay)
if(wage == 0):
print("\nInvalid hours or hourPay entered. Input must be postive >0")
else:
print("\nWage:",wage)
except Exception as e:
print("\nError: Invalid Input")
#---------- col_code.py ----------
def get_color_code(r,g,b):
if(r==1 and g == 1 and b == 1):
return "White"
elif(r==1 and g == 1 and b == 0):
return "Yellow"
elif(r==1 and g == 0 and b == 1):
return "Magneta"
elif(r==1 and g == 0 and b == 0):
return "Red"
elif(r==0 and g == 1 and b == 1):
return "Cyan"
elif(r==0 and g == 1 and b == 0):
return "Green"
elif(r==0 and g == 0 and b == 1):
return "Blue"
elif(r==0 and g == 0 and b == 0):
return "Black"
#function that sets boolean value into 0 or 1.
def bool_to_zero_one(val):
#by using == operator with True
#if user enters 0 then it will set to 0
#if user enters any other number it wil be set to 1
#in python 0 and False , 1 and True are same.
if(val == True):
return 1
else:
return 0
for i in range(3):
print("\nColor Code Test:",i+1)
try:
r = int(input("Enter r value(0/1): ").strip())
g = int(input("Enter g value(0/1): ").strip())
b = int(input("Enter b value(0/1): ").strip())
#considering 0/1 if user enters any value other than
#0/1 it will be converted to 0/1
r = bool_to_zero_one(r)
g = bool_to_zero_one(g)
b = bool_to_zero_one(b)
print("\nColor Code of %d%d%d is %s"%(r,g,b,get_color_code(r,g,b)))
except Exception as e:
print("\nError: Invalid Input")
#end of code.
#---------- phone_number.py-------
import re
def is_valid_phone_number(num):
#create a regular expression that will be used to
#compare given phone number format.
reg = re.compile("[(]\d{3}[)]-\d{3}-\d{4}")
if(reg.match(num) is not None):
return True
else:
return False
for i in range(3):
print("\nPhone Number Test:",i+1)
try:
#input must be same format need to include parenthesis also.
num = input("Enter Phone Number of format(###)-###-#### : ").strip()
if(is_valid_phone_number(num)):
print(num,"is Valid Phone Number")
else:
print(num,"is Invalid Phone Number")
except Exception as e:
print("\nError: Invalid Input")
#end of code.
#PLEASE LIKE THE ANSWER.