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

Your python program do not have to be modular, just develop the logic w/o modula

ID: 3624502 • Letter: Y

Question


Your python program do not have to be modular, just develop the logic w/o modular design.Develop the Python program for Chapter 5, Programming Exercise 12 (Caculating the Factorial of a Number) in 2nd edition textbook and save as <yourName or yourInititals>p04.py. You can just display the number and its factorial; however, for 15 extra credit points display the output in the following form (here the number entered to find the factorial of is 5):
5 ! = 1 * 2 * 3 * 4 * 5 * = 120 To do this you will have to utilize a comma at the end of a print list


the distance a vehicle travels can be calculated as follows
distance= speed* time

for example, it a train travels 40 miles per hour for three hours, the distance traveled is 120 miles. design a program that asks the user for the speed of a vehicle( in miles per hour) an how many hours it has traveled. it should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the out put

what is the speed of vehicle in mph? 40 [enter]
how many hours has it traveled? 3[enter]
hour distance traveled

1 40
2 80
3 120

Explanation / Answer

I answered the second part. Since it's two questions you should post them separately. Also it's hard to do the first part without knowing what Exercise 5 says.

Here's the second part:

def main():
    speed = int(raw_input("what is the speed of vehicle in mph? "))
    hours = int(raw_input("how many hours has it traveled? " ))
    print "hour distance traveled"
    print
    for hour in range(1,hours+1):
        print "%d %d"%(hour,hour*speed)

if __name__ == "__main__": main()