Question

Write a Python program: In main function the user is asked to enter distance traveled and...

Write a Python program:

In main function the user is asked to enter distance traveled and time and then send this information to a Python function that calculates and returns the speed of a car. The function will need to have parameters for distance traveled and time taken for the travel. The speed is calculated as:

Speed = distance traveled / time

In the main function show how to call this function in a print statement.

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

CODE:

def my_function(distance,time): #my_function definition

return distance/time #speed =distance/time
  
def main():
distance=int(input("Enter your distance value: ") ) #reading distance input from the keyboard
time=int(input("Enter your time value: ") ) #reading time input from the keyboard

print(my_function(distance,time)) #calling my_function and printing in the main functoin

if __name__ == '__main__':
main() #calling main function

OUTPUT:

case1:

Enter your distance value: 25
Enter your time value: 3
8.333333333333334

case2:

Enter your distance value: 25
Enter your time value: 5
5.0



Add a comment
Know the answer?
Add Answer to:
Write a Python program: In main function the user is asked to enter distance traveled and...
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
  • 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...

  • IN PYTHON Write a program that takes a user-input distance and speed and then calculates an...

    IN PYTHON Write a program that takes a user-input distance and speed and then calculates an ETA. Your program should work for ANY COMBINATION of distance and speed.

  • Python Programming 4th Edition: Write a program that asks the user for the number of feet....

    Python Programming 4th Edition: Write a program that asks the user for the number of feet. The program converts those feet to inches by using the formula ’12 * feet’. Hint: Define main () program Get the number of feet from the user Define variables Call a function feet_to_inches(feet) The function receives the number of feet and returns the number of inches in that many feet. The output should look like as follows: Enter the number of feet: If the...

  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

  • In Visual Basics - Program 2. Mileage Write a program which allows the user to enter...

    In Visual Basics - Program 2. Mileage Write a program which allows the user to enter the distance they have traveled by car in miles and the number of gallons of gasoline they used to travel the distance. Be sure to allow for decimal places for both values. Your results should show miles per gallon and kilometers per gallon. A kilometer is 0.61 miles, and this value must be stored as a constant. Your outputs must be formatted to 2...

  • Using python for this programming Factorial Ask the user to enter an integer number. Then print...

    Using python for this programming Factorial Ask the user to enter an integer number. Then print the factorial of that number Write a program to print the below ********                      (note: 8 stars) ******* ****** ***** **** *** ** * Ask the user to enter the speed of their car. Write an if-else statement that displays “Speed is normal” if the speed variable is within the range 24 to 56. If speed variable is outside this range it should display “speed...

  • Write a program that (in the main program) prompts the user for the (integer) model number...

    Write a program that (in the main program) prompts the user for the (integer) model number of their car. The main function should then call the function check defective which should • take in the model number of the car • check if the model number is 119, 179, 221, 780, or anything between 189 and 195, inclusive, which indicates the car is defective • print a message indicating whether or not the car is defective Note: this is should...

  • Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds...

    Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds the sum and average of a series of numbers he program should first prompt the user to enter total numbers of numbers are to be summed and averaged. It should then as for input for each of the numbers, add them, and print the total of the numbers and their average 2. Write a progra m that finds the area of a circle. The...

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

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

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