Question

THIS CODE IS IN PYTHON #This program calls a function from the main function def getInput():...

THIS CODE IS IN PYTHON

#This program calls a function from the main function

def getInput():

'''

This function gets the rate and the hours to calculate the pay

'''

userIn = float(input("Enter the rate: "))

print(userIn)

inputHours = float(input("Enter the hours: "))

print(inputHours)

def main():

getInput()

main()

  • YOU NEED TWO FUNCTIONS :
  1. main() function
  2. get_inputs function
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The explanation is provided in the form of the comments in the Code.

Code:

def getInput():
  
'''
This function gets the rate and the hours to calculate the pay
'''
  
# get the rate per hour as the input from the user, convert it float value
ratePerHour = float(input("Enter the rate(per hour): "))
  
# get the number of hours from the user
numOfHours = float(input("Enter the number of hours: "))
  
# return both the values so that total pay could be computed in the main function
return [ratePerHour, numOfHours]
  
def main():
  
# grab the two values by calling the getInput() function and store the result in appropriate variables
ratePerHour, numOfHours = getInput()
  
# print the Total Pay
print("Total Pay: " + str(ratePerHour*numOfHours))
  

main()

Add a comment
Know the answer?
Add Answer to:
THIS CODE IS IN PYTHON #This program calls a function from the main function def getInput():...
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
  • 6.5.1: Functions: Factoring out a unit-conversion calculation. PYTHON CODING Write a function so that the main program b...

    6.5.1: Functions: Factoring out a unit-conversion calculation.PYTHON CODINGWrite a function so that the main program below can be replaced by the simpler code that calls function mph_and_minutes_to_miles(). Original main program:miles_per_hour = float(input()) minutes_traveled = float(input()) hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('Miles: %f' % miles_traveled)Sample output with inputs: 70.0 100.0Miles: 116.666667

  • Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================")...

    Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================") print(" Baseball Team Manager") print("MENU OPTIONS") print("1 - Calculate batting average") print("2 - Exit program") print("=====================================================================")    def convert_bat(): option = int(input("Menu option: ")) while option!=2: if option ==1: print("Calculate batting average...") num_at_bats = int(input("Enter official number of at bats: ")) num_hits = int(input("Enter number of hits: ")) average = num_hits/num_at_bats print("batting average: ", average) elif option !=1 and option !=2: print("Not a valid...

  • USING PYTHON - Write a program that calls a function that prompts the user to enter...

    USING PYTHON - Write a program that calls a function that prompts the user to enter a real number. The function should verify that the user entered a valid real number, and should prompt the user to re-enter any invalid input. After a valid real number has been entered, the function should return the number as a number. To test your function, from a main function, call the function two separate times and print the sum of the two numbers...

  • ### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """...

    ### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """ Computes the minimum and maximujm grades from grades and creates a list of two student names: first name is the student with minimum grade and second name is the student with the maximum grade. grades: list of non-negative integers names: list of strings Returns: list of two strings """ def main(): """ Test cases for minmaxgrades() function """ input1 = [80, 75, 90, 85,...

  • In python using a def main() function, Write a function that will print a hello message,...

    In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...

  • If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly...

    If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly pay) If the employee is not a supervisor and she worked 40 hours or less calculate her paycheck as her hourly wage * hours worked (regular pay) If the employee is not a supervisor and worked more than 40 hours calculate her paycheck as her (hourly wage * 40 ) + (1 ½ times here hourly wage * her hours worked over 40) (overtime...

  • Help with Python code. Right now I'm creating a code in Python to create a GUI....

    Help with Python code. Right now I'm creating a code in Python to create a GUI. Here's my code: #All modules are built into Python so there is no need for any installation import tkinter from tkinter import Label from tkinter import Entry def calculatewages(): hours=float(nhours.get()) nsal=float(nwage.get()) wage=nsal*hours labelresult=Label(myGUI,text="Weekly Pay: $ %.2f" % wage).grid(row=7,column=2) return Tk = tkinter.Tk()    myGUI=Tk myGUI.geometry('400x200+100+200') myGUI.title('Pay Calculator') nwage=float() nhours=float() label1=Label(myGUI,text='Enter the number of hours worked for the week').grid(row=1, column=0) label2=Label(myGUI,text='Enter the pay rate').grid(row=2, column=0)...

  • # Find the error in the following program. def main():     # Get a value from...

    # Find the error in the following program. def main():     # Get a value from the user.     value = input("Enter a value.")     # Get 10 percent of the value.     ten_percent(value)     # Display 10 percent of the value.     print("10 percent of ", value, " is ", result) # The ten_percent function returns 10 percent # of the argument passed to the function. def ten_percent(num):     return num * 0.1 main()

  • PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """...

    PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as input. The output is the sentence after censoring all the matching words in the sentence. Censoring is done by replacing each character in the censored word with a * sign. For example, the sentence "hello yes no", if we censor the word yes, will become "hello *** no" Note: do not censor the...

  • Directions: Write a code for the following programming exercise in PYTHON!!!!!!! -Design a program that lets...

    Directions: Write a code for the following programming exercise in PYTHON!!!!!!! -Design a program that lets the user enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Here is what i got so far, but for some reason this code only print the Minimum and Maximum. its not printing the Average. def...

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