Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Zachary Wheeler
1,157 PointsHow to Make this Python Program work?
Travel on roads is a common activity. A few simple formulas can be used to help travelers plan their trips and avoid issues on the road.
I-15 is a North/South interstate highway with 400 miles of road in the state of Utah. There are mile markers every mile along the road starting with 0 in the Southwestern corner of the state, and ending near 400 on the Northern border of the state. Exits/on-ramps from/to the highway are numbered based on nearby mile markers. For example, the exit/on-ramp that connects to St. George Blvd. is numbered 8. Much of the stretch of I-15 in Utah has an upper speed limit of 80 miles per hour. Some areas have speed limits of 75 MPH or 65 MPH, depending on the road. Traveling too fast or too slow on the highway is dangerous to yourself and other travelers.
The distance between 2 exits can be calculated by subtraction. Just be sure to check which exit number is largest to make sure the distance is positive.
Travel time for a distance can be calculated by distance divided by speed.
Assignment
Write a program that asks the user for the locations of the on-ramp and exit they plan to use on the highway. It also needs to ask for how many hours until the traveler needs to arrive at their destination, and an expected average speed.
The program will calculate the distance to travel and the expected travel time, given the expected average speed.
Finally, the program will give one piece of advice, using this strategy:
if the expected average speed is above 80 MPH, the user will be travelling dangerously (and breaking the law), warn them if the expected average speed is less than 60 MPH, the user will be causing problems on the highway, warn them if the travel time is larger than the time when the user wants to arrive, tell the user how late they will be if none of the above contiditions occur, tell the user how far they will travel, and how long they have to leave in order to be on time. Additional Documentation
This page talks about I-15 in Utah.
I15 in Utah Potential Sessions
Sample 1
================================================== Welcome to the highway travel advisor. This application has been configured to work with travel on I-15 within the state of Utah. We'll ask for a few pieces of information, then give you advice on your travel.
Enter I-15 at what mile marker? 6 Exit I-15 at what mile marker? 306 How many hours from now do you want to arrive? 4.5 Expected average speed in MPH? 75
You will travel: 300 miles. Leave in the next 0.5 hours to be on time.
Thanks for using the highway travel advisor.
Sample 2
================================================== Welcome to the highway travel advisor. This application has been configured to work with travel on I-15 within the state of Utah. We'll ask for a few pieces of information, then give you advice on your travel.
Enter I-15 at what mile marker? 6 Exit I-15 at what mile marker? 306 How many hours from now do you want to arrive? 2.75 Expected average speed in MPH? 75
You won't be able to get there on time. You'll be 1.25 hours late.
Thanks for using the highway travel advisor.
Sample 3
================================================== Welcome to the highway travel advisor. This application has been configured to work with travel on I-15 within the state of Utah. We'll ask for a few pieces of information, then give you advice on your travel.
Enter I-15 at what mile marker? 9 Exit I-15 at what mile marker? 55 How many hours from now do you want to arrive? 1 Expected average speed in MPH? 55
Your speed is too slow. You'll be a hindrance to other traffic.
Thanks for using the highway travel advisor.
Sample 4
================================================== Welcome to the highway travel advisor. This application has been configured to work with travel on I-15 within the state of Utah. We'll ask for a few pieces of information, then give you advice on your travel.
Enter I-15 at what mile marker? 9 Exit I-15 at what mile marker? 55 How many hours from now do you want to arrive? .5 Expected average speed in MPH? 90
Your speed is dangerously high. Slow down.