Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We are interested in computing the speed of a car in \"meters per second\" or in

ID: 674599 • Letter: W

Question

We are interested in computing the speed of a car in "meters per second" or in "kilometers per hour" Write a script that prompts the user for three input values: An initial position in meters. A final position in meters. The elapsed time in seconds. Then, the script will use the menu function to present choices between 'speed in m/s', 'speed in km/hr', and 'nothing to compute'. According to the user's selection, the script will print the computed speed. Use an if-else statement to accomplish this. Modify the previous script to use a switch statement instead.

Explanation / Answer

def main():
while (True):
print "1. Calculate speed in m/sec"
print "2. Calculate speed in km/hr"
print "3. Nothing to compute"
print "Enter your choice ",
n = int(raw_input())
if (n == 1):
print "Enter the initial value in meters : ",
st = int(raw_input())
print "Enter the final value in meters : ",
en = int(raw_input())
print 'Time elapsed in second '
time = int(raw_input())
print 'Speed in m/s is ',(en-st)/time
elif (n == 2):
print "Enter the initial value in meters : ",
st = int(raw_input())
print "Enter the final value in meters : ",
en = int(raw_input())
print 'Time elapsed in second '
time = int(raw_input())
print 'Speed in km/hr is ',((en-st)/time)*3.6
else:
break

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote