Question: Python The two trains problem is a classic algebra problem. In this lab, we will write a program in python to solve every version of
Python
The two trains problem is a classic algebra problem. In this lab, we will write a program in python to solve every version of this problem.
This problem follows a basic pattern. The values will be replaced by variables in the below question.
Train A, traveling X miles per hour, leaves place1 heading toward place2, total miles away. At the same time Train B, traveling Y mph, leaves place2 heading toward place1. When do the two trains meet? How far are they from each city?
In this lab, you will write a problem that solves this problem. Then you will never have to do it by hand again.
When the meet is determined by
time in hours = (total miles)/(X mph+Y mph)
The distance from place1 is time*X.
The distance from place2 is time*Y.
You may assume that X, Y, and total will be integer values. The results should be given as decimal numbers rounded to 2 digits.
The command round(val, digits) can be used to round.
Your program should look like the below example. The solution to the Dr. Math example is given below.
Solve the Two Trains Problem. Enter First Speed: 70 Enter First Place: Westford Enter Second Speed: 60 Enter Second Place: Eastford Enter total distance: 260 Word Problem Train A, traveling 70 miles per hour, leaves Westford heading toward Eastford , 260 miles away. At the same time Train B, traveling 60 mph, leaves Eastford heading toward Westford . When do the two trains meet? How far are they from each city? Answers They meet after 2.0 hours. Train A is 140.0 miles from Westford Train B is 120.0 miles from Eastford
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
