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

Please write this program in Python and PLEASE make sure you run it making sure

ID: 3624728 • Letter: P

Question

Please write this program in Python and PLEASE make sure you run it making sure it works. Thank you SO much in advance :)

-Write a program that displays a menu allowing the user to select air, water, or steel. After the user has made a selection, he or she should be asked to enter the number of seconds the sound will travel in the selected medium. The program should then display the distance the sound will travel.

-The following table shows the approximate speed of sound in air, water, and steel.

Medium Speed

Air 1,100 feet per second
Water 4,900 feet per second
Steel 16,400 feet per second



-Write this program as a menu driven program where one of the menu selections is "quit" or "stop". The program is to repeatedly display the menu and process the selection until the "quit" or "stop" selection is made by the user. When the "quit" or "stop" selection is made, the program should stop.

Remember, distance=rate x time.

Explanation / Answer

See the original file (with proper indentation)

http://pastebin.com/XsewZDjC

 

values = [1100,4900,16400]
end = True
while(end):
print("1. Air ")
print("2. Water ")
print("3. Steel ")
print("0. Quit ")
userInput = raw_input("-->")
try:
userInput = int(userInput)
except:
print "Please enter a valid option"
continue
if userInput > 3 or userInput < 0:
print "Please enter a valid option"
continue
else:
if userInput == 0:
exit()
validSeconds = True
while(validSeconds):
print "Please enter a number of seconds"
seconds = raw_input("-->")
try:
seconds = int(seconds)
validSeconds = False
except:
print "Please enter a valid number of seconds"
print values[userInput-1]*seconds
print " "