Question

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 a separate function that is called by the main program.

There are 15 distances in the data (shown below).

Display the original value and its unit (miles/kilometers) and then the converted value and unit.

Data:

Miles 16

Miles 28

Kilometers 39

Kilometers 44

Miles 11

Kilometers 71

Miles 59

Kilometers 62

Kilometers 34

Miles 19

Miles 25

Kilometers 71

Kilometers 88

Kilometers 90

Miles 110

0 0
Add a comment Improve this question Transcribed image text
Answer #1
SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.


# convert miles to kilometers
def miles_to_km(miles):
    return miles / 0.6214


# convert kilometers to miles
def km_to_miles(km):
    return km * 0.6214


# main function
if __name__ == '__main__':
    # ask user for 15 times
    for i in range(15):
        # prompt user
        units = input('\nEnter units (Miles or Kilometers) : ')
        value = int(input('Enter value in '+str(units)+" : "))

        # check units and call the function
        if units == 'Miles':
            print(value, "Miles = ", miles_to_km(value), " Kilometers.")
        else:
            print(value, "Kilometers = ", km_to_miles(value), " Miles.")

===============

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Python code please!! Provide code and screenshots to both code and its output!!! Write a program...
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
  • plesse help! Kilometer Converter Design a modular program that asks the user to then converts that...

    plesse help! Kilometer Converter Design a modular program that asks the user to then converts that distance to miles. The conversion formula is as follows: enter a distance in kilometers, and Miles = Kilometers x 0.6214 THANKS!

  • PLEASE HELP WITH CODE PYTHON BASE.!!!!!!!! Tasks: Complete the following programs noted below: Problem 1: A...

    PLEASE HELP WITH CODE PYTHON BASE.!!!!!!!! Tasks: Complete the following programs noted below: Problem 1: A painting company has determined that for 112 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $35.00 per hour for labor. Write a program that asks the user to enter the square feet of wall space to be painted and the price of paint per gallon. The program should display the following data:...

  • Write a program that will convert miles to kilometers and kilometers to miles. The user will...

    Write a program that will convert miles to kilometers and kilometers to miles. The user will indicate both a number (representing a distance) and a choice of whether that number is in miles to be converted to kilometers or kilometers to be converted to miles Each conversion is done with a value returning function You may use the following conversions. 1 kilometer = .621 miles 1 mile = 1.61 kilometers Sample Run: Please input Convert miles to kilometers Convert kilometers...

  • Python help! I need help getting my code to increment the value. It keep calculating the...

    Python help! I need help getting my code to increment the value. It keep calculating the range over the same number and not moving up! this is the question Write a program named q1() that prompts the user for the starting and ending distance in Kilometers (km), and an increment value. It should then print the conversion table showing values for Kilometers, Miles (M) and Feet (ft). Each value should be displayed as they are calculated. and this is the...

  • Please show in MATLAB code using if and else statements if necessary Write a program in a script ...

    Please show in MATLAB code using if and else statements if necessary Write a program in a script file that converts a quantity of energy given in units of either J (Joules), Btu, or (ft-lb) to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of power in the new units using the fprintf command....

  • what code in python 3 would I use for this? Write a program that prompts the...

    what code in python 3 would I use for this? Write a program that prompts the user to guess a number between 0 and 10. Your program then picks a random number and tells the user whether their guess is too high, too low or right on! Don't forget to give the user an error if their number is below 0 or above 10. Don't forget to document your code.

  • 5. The Success Academy is organizing an event for its students. Write a Python program that...

    5. The Success Academy is organizing an event for its students. Write a Python program that prompts the user to enter the student's age and gender. The program should then display the day and time for the event registration based on the table below: Gender Registration Monday, 10:00am- 12:00pm Tuesday, 9:00am-12:00pm Wednesday, 9:00am-12:00pm Age Below 10 years old 10 years old and above Male Female Write a Python program that prompts the user to enter his/her monthly weight for the...

  • Can you help me write a Python 3.7 code for this question? Write a program using...

    Can you help me write a Python 3.7 code for this question? Write a program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a list. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The...

  • PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it...

    PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574 The program defines the following methods: Method feetToMeter() converts from...

  • Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a...

    Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a method that computes and returns the area of a square using the following header: public static double area ( double side) Write a main method that prompts the user to enter the side of a square, calls the area method then displays the area. Question 1a: Write a method that converts miles to kilometers using the following header: public static double convertToKilometers (double miles)...

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