# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 4/22/2015 #Program Title: Chapter 5 Programming Excercise 6.py #(Distance Traveled) #Program Description: This program prompts a user for the speed of a vehicle (in miles per hour) #and how many hours it has traveled. The program will then display the distance the vehicle has #travled for each hour. # ------------------------------------------------------------ # Prints the distance traveled def printDistanceTraveled(vehicleSpeed, vehicleMilage): print '\n Hour Distance Traveled \n ----------------------------------------' for i in range(1,vehicleMilage + 1): distance = vehicleSpeed * i print ' {0} {1}miles' .format(i,distance) # prompts user for input. def promptForNumber(strPrompt): userInput = int(raw_input(strPrompt + ": ")) print '{}' .format(userInput) return userInput #main driver function def main(): try: printDistanceTraveled(promptForNumber("What is the speed of the vehicle in mph?"), promptForNumber("How many hours has it traveled?")) except (ValueError): print '\n\nInvalid input. You have entered a non integer. Please enter an integer' except (EOFError): print '\n\nInvalid input. You have forgotten to add input. Please Reset program and Please enter an integer' main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question