Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
I need python help! Please!?
################################################################################
# Purpose of the Program: This program will Calculate distance traveled
# Programmer: Jennifer Bauer
# Date: Tuesday, May 5, 2009
# Week 9 Homework
# File Name: distance_traveled.py
#################################################################################
def main():
answer='y'
while answer=='y' or answer=='Y':
#
display_information()
#
speed=get_and_validate_speed()
#
hours=get_and_validate_hours()
#
distance=calculate_distance_traveled(speed,hours)
#
print_distance_traveled(speed,hours)
#
answer=raw_input('Do you Want to Continue. Press (Y/y):')
#
display_end_of_program()
#*** The following are the Definitions of the Functions that are being called by the main program ***
def display_information():
print '****************************************************************************'
print '************* Distance Traveled ****************'
print '************ Calculate the distance a vehicle travels ****************'
print '****************************************************************************'
#
def get_and_validate_speed():
speed=input('Enter speed of vehicle in MPH: ')
while speed<1 or speed>250:
speed=input('Invalid Speed. Please enter a number between 1 and 250: ')
return speed
#
def get_and_validate_hours():
hours=input('Enter number of hours: ')
while hours<1 or hours>100:
hours=input('Invalid Hours. Please enter a number between 1 and 100: ')
return hours
#
def calculate_distance_traveled(speed,hours):
distance=hours*speed
return distance
#
def print_distance_traveled(speed,hours):
print ' Hour Distance Traveled in Miles'
print '-'*60
counter=1
while hours>=speed:
print '**** Hours Distance Traveled ****************'
print '**** ------ ------------------- ***************'
distance=hours*speed
time +=1
#
def display_end_of_program():
print '*************************************************************************'
print '********************** E N D O F P R O G R A M ************************'
print '*************************************************************************'
print '********************** Programmer: Jennifer Bauer *************************'
#
main()
thats my program. And I need the outcome to list the hours like
Hours
1
2
3
4
then the distance traveled like that in the same line. Can anyone help me?
1 Answer
- omLv 61 decade agoFavorite Answer
Your print_distance procedure is a bit confused. It should look more like this:
def print_distance_traveled(speed,hours):
print
print 'Hour', 'Distance Traveled in Miles'
print '-'*60
counter=1
while counter <= hours:
distance=counter*speed
print counter, distance
counter +=1
print