Question

PYTHON Write a function called hourly_employee_input that asks the user for a name (string), hours worked...

PYTHON Write a function called hourly_employee_input that asks the user for a name (string), hours worked (int) and an hourly pay rate (float) and prints a string including the information.

  • Call the function, entering expected values, numbers in appropriate range
  • Call the function, entering negative numbers
  • Call the function, entering bad input (letters, symbols)
  • What do you need to add to your function for bad input? Handle the bad input so your program doesn't end when receiving bad input
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#method to calculate total pay
def hourly_employee_input():
#get input from user
name = input("Enter name: ")
hours = input("Enter hours: ")
  
#check hours
if hours.isdigit():
hr = int(hours)
else:
print("Invalid Input!")
return
  
payRate = float(input("Enter hourly pay rate: "))
  
#check pay rate
if isinstance(payRate, float):
rate = payRate
else:
print("Invalid Input!")
return
  
#calculate total pay
totalPay = hr * rate
  
#display total pay
print("Total pay of", name,"=", totalPay)
  
#method calling
hourly_employee_input()

The screenshot of the above code is given below:

#method to calculate total pay def hourly_employee_input: #get input from user name = input(Enter name: ) hours = input (E

OUTPUT:

Enter name: ABC Enter hours: 5 Enter hourly pay rate: 10.25 Total pay of ABC = 51.25

Enter name: DEF Enter hours: A Invalid Input!

Add a comment
Know the answer?
Add Answer to:
PYTHON Write a function called hourly_employee_input that asks the user for a name (string), hours worked...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python code that asks a string from the user and prints only the lower...

    Write a Python code that asks a string from the user and prints only the lower case letters in that string

  • Python Use the Design Recipe to write a function called running_average that repeatedly asks the user...

    Python Use the Design Recipe to write a function called running_average that repeatedly asks the user to input integers at the keyboard until they type the word done. Return the average of the values they entered. You may assume the user will only enter integers or "done". Include a docstring!

  • Write a program to prompt the user for hours and rate per hour using input to...

    Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per...

  • In a file called First SecondNext.java, write a program that: • Asks the user to enter...

    In a file called First SecondNext.java, write a program that: • Asks the user to enter a string that contains at least five letters. It is OK if your program crashes when the user enters a string with length less than 5. • Stores that string in a variable called s. • Creates a variable called "first", and sets it equal to the first letter of s. • Creates a variable called "second", and sets it equal to the second...

  • Use PYTHON3 to create a program that asks the user for their name, and then prints...

    Use PYTHON3 to create a program that asks the user for their name, and then prints their initials. You must create a function called getInitials() that takes the name string and prints out the initials. It must be case insensitive and the initials must be printed in upper case. The program must contain a main() and a function called getInitials(), implemented as described in the function header comment given below. (You should include this function header comment in your own...

  • IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer...

    IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer and prints the digits using math function, as shown below. You are not allowed to process the number as a string. You must process the number using standard arithmetic operators (+, *, /, %, etc.) >>> printDigits() Enter n: 1234 1 2 3 4 >>> printDigits() Enter n: 9876 9 8 7 6 >>>

  • PYTHON 4. Define a function that takes two arguments: a string called strText and a number...

    PYTHON 4. Define a function that takes two arguments: a string called strText and a number called intNumber. This function will use a repetition structure (a While or For loop) to print strText intNumber of times. Call this function. 5. Get an input from the user that is a file name with an extension (e.g., "myfile.ipynb" or "myfile.txt"). Print only the characters that follow the "." in the file name (e.g., "ipynb" and "txt"). 6. Ask the user for 5...

  • Java Question, I need a program that asks a user to input a string && then...

    Java Question, I need a program that asks a user to input a string && then asks the user to type in an index value(integer). You will use the charAt( ) method from the string class to find and output the character referenced by that index. Allow the user to repeat these actions by placing this in a loop until the user gives you an empty string. Now realize that If we call the charAt method with a bad value...

  • Write a C Program that asks the user to input a string and then the user...

    Write a C Program that asks the user to input a string and then the user is prompted back whether the input string is a “Palindrome Word” or not. (A Palindrome Word reads the same backward or forward, eg. madam, racecar, etc.) Your program should contain a function that accepts the input string from the main function and returns a value indicating whether the input string is a Palindrome or not. Use Pointers to traverse the string.

  • Write a Python program that asks the user to type in their three quiz scores (scores...

    Write a Python program that asks the user to type in their three quiz scores (scores between 0 and 100) and displays two averages. The program should be written so one function gets the user to input a score, another function takes the three scores and returns the average of them. And another function takes the three scores and averages the two highest scores (in other words, drops the lowest). Each of these functions should do the computation and return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT