# Room Rent Calculation with Python Assignment Solution

## Calculate the Cost of Renting Room

Write a Python assignment program to calculate the cost of renting rooms at a hotel.

Process:

The cost of renting a room at a hotel is, say \$100.00 per night. For special occasions, such as a wedding or a conference, the hotel offers a special discount as follows:

If the number of rooms booked is between 1 and 10, the discount is 10%; more than 10, but less than or equal to 20, the discount is 20%; and more than 20 rooms, the discount is 30%.

If rooms are booked for at least 3 days, then there is an additional 5% discount.

If the number of rooms booked is 0 or less, issue an error message and do not perform any calculation nor produce any other output.

Your program prompts the user to enter:

• The cost of renting one room,
• The number of rooms booked,
• The number of days the rooms are booked, and
• The sales tax (as a percent, i.e. 10 for 10%).

The program outputs:

• The cost of renting one room,
• The discount on each room is a percent,
• The discount is based on the number of days as a percent,
• The number of rooms booked,
• The number of days the rooms are booked,
• The total cost of the rooms before tax,
• The sales tax (calculated based on total bill before any discounts), and
• The total billing amount.

SAMPLE RUN:

Make sure to fully test your code.

What is the cost of renting one room for one night? 100

How many rooms are booked? 5

How many days are the rooms booked for? 2

What is the sales tax? (For example, if tax is 15.5%, enter 15.5.) 16

Cost for one room: 100.0

Discount based on number of rooms: 10.0%

Discount based number of days: 0.0%

Number of rooms: 5

Number of days: 2

Total cost before Tax: \$900.0

Tax: \$160.0

Total Bill: \$1060.0

Or:

What is the cost of renting one room for one night? 100

How many rooms are booked? 12

How many days are the rooms booked for? 4

What is the sales tax? (For example, if tax is 15.5%, enter 15.5.) 10

Cost for one room: 100.0

Discount based on number of rooms: 20.0%

Discount based number of days: 5.0%

Number of rooms: 12

Number of days: 4

Total cost before Tax: \$3600.0

Tax: \$480.0

Total Bill: \$4080.0

Or:

What is the cost of renting one room for one night? 10

How many rooms are booked? 0

Invalid number of rooms - program will terminate

Solution:

```''' Your full name: Course number and course section number: Date of completion: ''' def rentingroom(): #The following function prompts user for inputs like rant of room, no of rooms, no of days, tax. #It caluculates discount based on the input data #It prints discount availed, Total cost before tax, tax, total bill. # the following lines prompt for rent and Number of rooms. rent_of_room = float(input('What is the cost for renting one room for one night?')) no_of_rooms = int(input('How many rooms are booked?')) # The following if condition checks for validity of user input of number of rooms. if no_of_rooms <= 0: print('Invalid number of rooms - program will terminate') else: # prompts user for no of days and sales tax. no_of_days = int(input('How many days are the rooms booked for?')) salestax = int(input('What is the sales tax? (For example, if tax is 15.5%, enter 15.5.)')) discount_percent = 0.0 discount_percent_days = 0.0 # the following conditions check the user inputs above and gives user discount accordingly. if no_of_rooms >=1 and no_of_rooms <= 10: discount_percent = 10.0 elif no_of_rooms >10 and no_of_rooms <= 20: discount_percent = 20.0 else: discount_percent = 30.0 if no_of_days >=3: discount_percent_days = 5 # prints user input data along with discount, total cost before tax, tax, total bill. print("\n\n\n") print(f'Cost for one room: {round(rent_of_room,1)}') print(f'Discount on based on number of rooms: {discount_percent}%') print(f'Discount based number of days: {discount_percent_days}%') print(f'Number of rooms: {no_of_rooms}') print(f'Number of days: {no_of_days}') cost_before_discount = no_of_rooms*no_of_days*rent_of_room total_cost_beforetax = cost_before_discount - (discount_percent_days + discount_percent)*cost_before_discount/100 print(f'Total cost before Tax: {round(total_cost_beforetax, 1)}') Tax = salestax*cost_before_discount/100 print(f'Tax: {round(Tax, 1)}') total_bill = total_cost_beforetax + Tax print(f'Total Bill: {round(total_bill, 1)}') rentingroom() # In[ ]: # In[ ]: ```