Question

tubwub.py You are working for a software company called TubWub, which is trying to build an...

tubwub.py

You are working for a software company called TubWub, which is trying to build an app which helps people locate cheap admission tickets to nearby events. The head office of TubWub is located at latitude 40.740230 degrees, longitude -73.983766degrees. As a first step towards getting your software up and running, write a program which takes as input some information about an event, and then prints out the distance from the TubWub head office to the event, along with a decision about how many tickets to buy to the event.The program should ask the user to enter:

•the latitude and longitude for the event’s location,

•a price per ticket,

•and whether or not the event is “hot” (the user will answer this question with y or n).

The program should first calculate the distance from TubWub headquarters to the event, using the follow process to calculatethe approximate distance between two locations in kilometers:

1. Calculate ∆Lat, the difference between the latitudes. Multiply by 111.048 to convert the degree difference to kilometers.

2. Calculate ∆Long, the difference between the longitudes. Multiply by 84.515 to convert the degree difference to kilometers.

3. The distance between the locations is then found√(∆Lat)2+ (∆Long)2.

(We’re assuming that the event entered is in or close to New York City, so that we can treat the Earth as essentially flat.)The program should then decide how many tickets to buy based on the following rules: no tickets should be bought if the event is more than 3 kilometers; no tickets should be purchased if the event is not“hot”; and if neither of the above applies,the number of tickets purchased should be the greatest integer such that the total price of the tickets does not exceed 150.00dollars

A sample run should look like:

Enter latitude of event: 40.768

Enter longitude of event: -73.972

Price per ticket: 60Is it hot?: y

Distance = 3.240166507609296

Buy 0 tickets

Challenge: instead of using the “Flat Earth” approximation, use spherical geometry to calculate the distance (this will require you to use an approximation for the radius of the Earth, for which you can use 6371 km). Your distances should beslightly different than my sample ones.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import math

latitude1 = 40.740230
longitude1 = -73.983766

# Take inputs
latitude2 = float(input('Enter latitude of event: '))
longitude2 = float(input('Enter longitude of event: '))
price = float(input('Price per ticket: '))
hot = input('Is it hot?: ')

# Calculate  ∆Lat and  ∆Long
lat = (latitude1 - latitude2) * 111.048
long = (longitude1 - longitude2) * 84.515

# Calculate distance and print
distance = math.sqrt(math.pow(lat, 2) + math.pow(long, 2))
print('Distance =', distance)

# Calculate tickets and print
tickets = 0
if hot.lower() == 'y' and distance <= 3:
    tickets = 150 // price

print('Buy', int(tickets), 'tickets')

SCREENSHOT



OUTPUT

Add a comment
Know the answer?
Add Answer to:
tubwub.py You are working for a software company called TubWub, which is trying to build an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer all questions for UPVOTE LOCATION: Cleveland, Ohio DREAM LOCATION: Rome, Italy PRECALCULUS: VECTORS Directions: Suppose that you plan to take a trip to your dream destina...

    Please answer all questions for UPVOTE LOCATION: Cleveland, Ohio DREAM LOCATION: Rome, Italy PRECALCULUS: VECTORS Directions: Suppose that you plan to take a trip to your dream destination. You would like to know the shortest distance between your starting point and your destination. When calculating distances on a plane, you need only consider two dimensions because you are on a flat surface. However, when finding distances between two points on Earth, you must take into the account the curvature of...

  • The following C++  code contains an incomplete program that should be able to calculate the distance between...

    The following C++  code contains an incomplete program that should be able to calculate the distance between a series of geocoded locations. Two parts of the program need to be completed: 1. The portion of the main() function that calculates the distances between each of the hard-coded 5 locations, and stores it in a two-dimensional array declared as distances. 2. A portion of the calculateDistanceBetweenLocations(l1, l2) function; omitted code spaces are designed with a // TODO: comment. The code is properly...

  • You are working as a software developer for a large insurance company. Your company is planning...

    You are working as a software developer for a large insurance company. Your company is planning to migrate the existing systems from Visual Basic to Java and this will require new calculations. You will be creating a program that calculates the insurance payment category based on the BMI score. Your Java program should perform the following things: Take the input from the user about the patient name, weight, birthdate, and height. Calculate Body Mass Index. Display person name and BMI...

  • C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the...

    C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the Facility.cpp file and the other files are included in case they're needed for understanding. I was able to complete the mayday.cpp file but am stuck on Facility. The following link contains a tar file with the files provided by the professor. Thank you so much in advanced! http://web.cs.ucdavis.edu/~fgygi/ecs40/homework/hw4/ Closer.h: #ifndef CLOSER_H #define CLOSER_H #include <string> #include "gcdistance.h" struct Closer { const double latitude, longitude;...

  • Using Jupyter, Please answer the following question: Please import alic.txt and cound the number of words...

    Using Jupyter, Please answer the following question: Please import alic.txt and cound the number of words and characters in it. We need to count the number of words in the txt file and find the most repeated one. In the program, first convert all words to lower case and then convert the first character to the upper case. Then we need to do the analysis. We are not interested in the following words: The, A, And, To, It alice.txt file:...

  • What happened on United flight 3411?What service expectations do customers have of airlines such ...

    What happened on United flight 3411?What service expectations do customers have of airlines such as United and How did these expectations develop over time? Thank You! In early April 2017, United Airlines (United), one of the largest airlines in the world, found itself yet again in the middle of a service disaster this time for forcibly dragging a passenger off an overbooked flight. The incident was to become a wake-up call for United, forcing it to ask itself what to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT