



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Files to submit:
**1. riderHeight.py
For Help: ย Newsgroups โ see course syllabus for more detailed information ย TA Helpdesk โ schedule will be posted on class website ย Email TAs
Notes: ย Think through the logic of each of the problems before you start coding anything ย Donโt forget to include the required comments and collaboration statement (as outlined on the course syllabus) ย Be careful when you submit multiple files to WebWork ย Retrieve your submission from WebWork and rerun it to be sure it still works okay ย Do not wait until the last minute to do this assignment incase you run into problems ย If you find an error in the homework assignment, let a TA know immediately
Remember all of the functions we used for HW1: raw_input(), float(), str()
It might help to look at the Boolean operators: http://docs.python.org/lib/boolean.html And the comparison operators: http://docs.python.org/lib/comparisons.html
Also you will need math.ceil() for part 2: (http://docs.python.org/lib/module-math.html)
ceil ( x ) Return the ceiling of x as a float, the smallest integer value greater than or equal to x.
Basically, math.ceil() always rounds the number up to the next integer. For example:
math.ceil(1)
math.ceil(1.2)
math.ceil(1.0000000001)
In anticipation of GT Day at Six Flags (http://sixflags.gatech.edu/) on Friday, Sept. 15, 2006, we have begun looking at the height requirements of 10 popular rides.
RIDE Height Requirements Acrophobia 54" or greater Batman 54" or greater Georgia Cyclone 48" or greater Ninja 48" or greater Coyote Canyon Blaster 36" or greater Thunder River 36" or greater Log Flume Between 34" and 42" Bugs Bunny World Between 34" and 42" Airplane Ride No height restriction (everyone can ride) Haunted House No height restriction (everyone can ride)
Write a Python program which prompts a user to enter their height. Then display a list of the rides the rider CAN and CANNOT ride based on their height. Be sure to number the results and display a summary at the end that lists the number of rides the rider CAN and CANNOT ride. (This two numbers should always add up to 10)
Although your output does not need to match the sample output exactly, it should serve as a good guide.
Assume that we will input valid integers between 0 and 100.
Sample output:
Please enter height in inches: 5 Rider is permitted to ride on: 1 - Airplane Ride 2 - Haunted House
Rider CANNOT ride on: 1 - Acrophobia 2 - Batman 3 - Georgia Cyclone 4 - Ninja 5 - Coyote Canyon Blaster 6 - Thunder River 7 - Log Flume 8 - Bugs Bunny World
Rider can ride on a total of 2 rides! Rider cannot ride on a total of 8 rides!
You are working for a travel website that wants to launch a Taxi Fare comparison for Atlanta. There are 3 taxi companies that each have different rate structures, as follows:
Taxi Company A $2.40 โ First mile $0.61 โ Each additional mile
Taxi Company B $0.92 โ Each mile (no special rate for the first mile)
Taxi Company C $3.78 โ First 2 miles (this charge includes both miles, it is not per mile) $0.54 โ Each additional mile
If there is a fraction of a mile, always round up and charge the complete mileage fee. For example: A 2.5 mile cab ride would cost: A -$3.62 B - $2.76 C - $4.
First, in order to help us write our program, we are going to create a function called cheapest. It needs to take in 3 numbers and return the lowest of all of them. Here is a function called cheaper which returns the lowest of 2 numbers. You can base your function off of this one, but be sure to change it so it works with 3 numbers.
For example: def cheaper(x,y): if x<y: return x else: return y
!!! Be sure to place this function at the TOP of your taxiFare.py file!
Now, write the program that will actually compare the fares for a given distance. Prompt the user for the number of miles. Your program should only accept values between 0 and 15. If they enter a negative number, print nothing but this error message:
Invalid entry - negative number
If they enter exactly 0, print this: Invalid entry - cannot go 0 miles
If they enter a number over 15, print this: Invalid entry - cannot use a taxi for that long"
If the number they enter is valid (greater than 0 and less than or equal to 15), continue on to the rest of the program.
Calculate the rate that each company would charge and print out each rate with a label. You will need to use the math.ceil() cfunctoin
A - $3.62 B - $2.76 C - $4.
Once again, do not worry about rounding to two decimal places, but DO include the dollar sign. It will probably be helpful to use math.ceil(), so be sure to import the math module.
Now, using your function cheapest() that you wrote earlier, determine which company is cheapest for the given distance and what their price is:
Company B is cheapest! Cheapest taxi fare for 2.5 miles is $2.
Donโt forget you can compare output of functions to another variable to see if they are equal.
For example:
x = 2 y = 4 if x==math.sqrt(y): print "YES!"
"YES!โ
Sample output:
Please enter number of miles: Invalid entry - cannot go 0 miles
Please enter number of miles: A -$3.62 B - $2.76 C - $4. Company B is cheapest! Cheapest taxi fare for 3 miles is $2.
Please enter number of miles: A -$9.11 B - $11.04 C - $9. Company A is cheapest! Cheapest taxi fare for 12 miles is $9.
Please enter number of miles: Invalid entry - cannot use a taxi for that long