Question

6.5.1: Functions: Factoring out a unit-conversion calculation.

PYTHON CODING

Write 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.0

Miles: 116.666667

CHALLENGE 6.5.1: Functions: Factoring out a unit-conversion calculation. ACTIVITY Write a function so that the main program b


7 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1


# Function written to simplify main code

def mph_and_minutes_to_miles(miles_per_hour, minutes_traveled):

    hours_traveled = minutes_traveled / 60.0

    miles_traveled = hours_traveled * miles_per_hour

    return miles_traveled



miles_per_hour = float(input())

minutes_traveled = float(input())


print('Miles: %f' % mph_and_minutes_to_miles(miles_per_hour, minutes_traveled))


Add a comment
Know the answer?
Add Answer to:
6.5.1: Functions: Factoring out a unit-conversion calculation. PYTHON CODING Write a function so that the main program b...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • CHALLENGE ACTIVITY 13.2.1: Functions: Factoring out a unit-conversion calculation Write a function so that the main...

     CHALLENGE ACTIVITY   13.2.1: Functions: Factoring out a unit-conversion calculation. Write a function so that the main 0 code below can be replaced by the simpler code that calls function MphAndMinutesToMiles 0 . Original main():13. 2.2: Function stubs: Statistics. Define stubs for the functions called by the below main0. Each stub should print "FIXME: Finish FunctionName0" followed by a newline, and should return -1. Example output:

  • 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 : main() function get_inputs function

  • #function to covert kilometer to miles #takes km input as an argument and return the calculation...

    #function to covert kilometer to miles #takes km input as an argument and return the calculation def kilometer_to_miles(km): return km * 0.6214 #function to covert miles to kilometer #takes miles input as an argument and return the calculation def miles_to_kilometer(miles): return miles/0.6214 #Main function to find the distance #by calling either of the two functions #prompt the user to enter his/her choice of distance conversion restart = 0 while (restart == 'y'): user_input = input ("Enter k to convert kilometer...

  • In C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

  • C++ Write a function so that the main() code below can be replaced by the simpler...

    C++ Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original main(): int main() { double milesPerHour; double minutesTraveled; double hoursTraveled; double milesTraveled; cin >> milesPerHour; cin >> minutesTraveled; hoursTraveled = minutesTraveled / 60.0; milesTraveled = hoursTraveled * milesPerHour; cout << "Miles: " << milesTraveled << endl; return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <iostream> using...

  • 1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat,...

    1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat, a recursive function that takes two alphabetically-ordered strings and merges them, leaving the letters in alphabetical order. Note that the strings may be different lengths. a main method that inputs two ordered strings and calls the orderedConcat method to return a resulting merged, ordered string. Your main method should print the two input strings and the result. Note: You may not use any of...

  • Python 3 please. 6.27 (Functions) HW: Driving cost - functions Write a function DrivingCost with input...

    Python 3 please. 6.27 (Functions) HW: Driving cost - functions Write a function DrivingCost with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. Ex: If the function is called with 50 20.0 3.1599, the function returns 7.89975. Define that function in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both floats). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your DrivingCost function three...

  • FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice...

    FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...

  • In python coding please add functions/methods at least 3 of them. Please just adjust code I...

    In python coding please add functions/methods at least 3 of them. Please just adjust code I have provided and update it to include functions/methods. You can rearrange the code, edit or delete parts to add functions/methods. PLEASE DO NOT make a Whole New code. Please use what I have provided. I do not need a whole different code, just edits on what I have provided. THIS is the original question:Design a modular program that asks the user to enter the...

  • Python code please!! Provide code and screenshots to both code and its output!!! Write a program...

    Python code please!! Provide code and screenshots to both code and its output!!! Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is: Miles = Kilometers X 0.6214 Kilometers = Miles / 0.6214 Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles The conversion MUST be done as...

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