Question

In: Computer Science

CODE IN PYTHON: Your task is to write a simple program that would allow a user...

CODE IN PYTHON:

Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip.

User will also enter the number of days it will take to complete the trip. For each night (day-1 nights), user will need a hotel. We will ask for the number of stars for the hotel the user wants to stay. 5 star hotel costs $250 per night. 4 star hotel costs $180 per night. 3 star hotel costs $120 per night, 2 star hotel costs $100 per night and finally 1 star hotel costs $50 per night. Using the hotel costs and the number of nights users will need to stay at a hotel, you can compute the hotel cost of the trip.

Please note that 5 star and 4 star hotels give 10% discount if the user will be staying more than 2 nights -- (these are chain hotels, so even if you are staying at different locations discount apply).

We should also account for the cost of meals. This depends on the type of hotel the user is staying. In general, we take 20% of hotel cost as the meal cost (after 10% hotel discount if applicable).

Example Run #1

Distance: 350

MPG : 15

Gas Price: 3.79

Days Traveling : 3

Hotel Stars (1-5) : 3

Your total cost is $376.43333333333334

Example Run #2

Distance: 400

MPG : 20

Gas Price: 2.99

Days Traveling: 1

Hotel Stars (1-5): 5

Your total cost is $59.800000000000004.

Example Run #3

Distance: 150 MPG : 25 Gas Price: 1.99 Days Traveling : 2 Hotel Stars (1-5): 5 Your total cost is $311.94.

Solutions

Expert Solution

#main.py

def calculate_gas_price(distance, mpg, gas_price):
    """
    function to calculate gas price
    :param distance:
    :param mpg:
    :param gas_price:
    :return: gas price
    """
    return (distance / mpg) * gas_price


def calculate_hotel_and_meal_price(days, hotel_star):
    """
    function to find stay price
    :param days:
    :param hotel_star:
    :return: stay price
    """

    # mapping of star and price
    hotel_price_map = {
        5: 250,
        4: 180,
        3: 120,
        2: 100,
        1: 50
    }
    if days <= 1:
        return 0
    hotel_price = hotel_price_map.get(hotel_star, 0) * (days-1)
    discount = 0
    # if 4 or 5 star hotel and stay more than 2 night
    if (days - 1) > 2 and hotel_star in (5, 4):
        discount = (hotel_price * 10) / 100
    # subtracting discount if any
    hotel_price -= discount
    # adding meal price
    meal_price = (hotel_price * 20) / 100
    hotel_price += meal_price
    return hotel_price


def main():
    distance = float(input('Distance: '))
    mpg = float(input('MPG: '))
    gas_price = float(input('Gas Price: '))
    days_travelling = int(input('Days Traveling: '))
    hotel_star = int(input('Hotel Stars (1-5) :'))
    # calling function and showing price
    gas_price = calculate_gas_price(distance, mpg, gas_price)
    hotel_and_meal_price = calculate_hotel_and_meal_price(days_travelling, hotel_star)
    print('Your total cost is $' + str(gas_price + hotel_and_meal_price))


if __name__ == '__main__':
    main()

# OUT

Please do let me know if u have any concern..


Related Solutions

Write a python program that will allow a user to draw by inputting commands. The program...
Write a python program that will allow a user to draw by inputting commands. The program will load all of the commands first (until it reaches command "exit" or "done"), and then create the drawing. Must include the following: change attributes: color [red | green | blue] width [value] heading [value] position [xval] [yval] drawing: draw_axes draw_tri [x1] [y1] [x2] [y2] [x3] [y3 draw_rect [x] [y] [b] [h] draw_poly [x] [y] [n] [s] draw_path [path] random random [color | width...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
Write a GUI based Python program that will allow the user to perform (i) generate RSA...
Write a GUI based Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as well....
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x)...
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”....
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”. It takes one or more files and displays requested number of lines from the ending. If number is not specified, then it print 10 lines by default.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT