Question

In: Computer Science

**Use Python 3.7.4 *** 1. Ask the user for the number of hours worked, salary per...

**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.

Solutions

Expert Solution

#------- 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.


Related Solutions

Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the user to enter the student names and scores as shown. Output the name and score of the student with the 2nd lowest score. NOTE: You may assume all students have distinct scores between 0 and 100 inclusive and there are at least 2 students NOTE: You may only use what has been taught in class so far for this assignment. You are not allowed...
Write a while loop to ask the user to type number of hours(double) they work per...
Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than 0 and less than 5, then:  salary = numberofhours * 12, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 12, then: salary = numberofours * 14, loop continues, the user can type another number If...
In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
The number of hours worked per year per adult in a state is normally distributed with...
The number of hours worked per year per adult in a state is normally distributed with a standard deviation of 37. A sample of 115 adults is selected at random, and the number of hours worked per year per adult is given below. Use Excel to calculate the 98% confidence interval for the mean hours worked per year for adults in this state. Round your answers to two decimal places and use ascending order. Number of hours 2250 1987 2029...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in a list called myList. Compute and print out the sum and average of the items in the list. Print the numbers that are divisible by 2 from myList. b. Instead of using a list to store the numbers, create a loop to accept the numbers from the user, and find the average of all the numbers. Hint: use an accumulator to store the numbers...
Write, save, and run a Python program Ask the user to enter a number of grams....
Write, save, and run a Python program Ask the user to enter a number of grams. Your program converts that to whole tones, then whole kilograms and whatever is left is in grams. It prints the entered grams , tones , kilograms and the remaining grams.      4 marks for i in range(0,10): print(i) 2    what is wrong in the above python code? display your explanation using print statement. mark 3    insert the following comments into your program of part...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they type DONE to quit. The program should DOUBLE each of the digits in the number and display the original entry AND the SUM of the doubled digits. Hint: Use the // and % operators to accomplish this. Print the COUNT of entries that were invalid Examples: if the user enters 93218, the sum of the doubled digits is 18+6+4+2+16 = 46. User Entry Output...
in java code Modify your program as follows: Ask the user for the number of hours...
in java code Modify your program as follows: Ask the user for the number of hours worked in a week and the number of dependents as input, and then print out the same information as in the initial payroll assignment. Perform input validation to make sure the numbers entered by the user are reasonable (non-negative, not unusually large, etc). Let the calculations repeat for several employees until the user wishes to quit the program. Remember: Use variables or named constants...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT