Question

Code comments explain and facilitate navigation of the code python import sys rentalcode = input("(B)udget, (D)aily,...

Code comments explain and facilitate navigation of the code

python

import sys

rentalcode = input("(B)udget, (D)aily, or (W)eekly rental?\n").upper()
if rentalcode == 'B' or rentalcode == 'D':
    rentalperiod = int(input("Number of Days Rented:\n"))
else:
    rentalperiod = int(input("Number of Weeks Rented:\n"))

# Pricing
budget_charge = 40.00
daily_charge = 60.00
weekly_charge = 190.00

#Second Section 2
odostart =int(input("Starting Odometer Reading:\n"))
odoend =int(input("Ending Odometer Reading:\n"))
totalmiles = int(odoend) - int(odostart)

if rentalcode == 'B':
    milecharge = 0.25 * totalmiles
if rentalcode == "D":
    averagedailymiles = int(totalmiles) /int(rentalperiod)
    if averagedailymiles <= 100:
        totalmiles = 0
    elif averagedailymiles > 100:
        extramiles = averagedailymiles - 100
    milecharge = .25 * extramiles
if rentalcode == "W" and averagedailymiles > 900:
    milecharge = rentalperiod * 100
elif rentalcode == "W" and averagedailymiles <= 900:
    milecharge = 0

if rentalcode == "B":
    basecharge = rentalperiod * budget_charge
elif rentalcode == "D":
    basecharge = rentalperiod * daily_charge
elif rentalcode == "W":
    basecharge = rentalperiod * weekly_charge
amtdue = float(basecharge) +float(milecharge)

print("Rental Summary")
print("Rental Code:" + str(rentalcode))
print("Rental Period:" + str(rentalperiod))
print("Starting Odometer:" + str(odostart))
print("Ending Odometer:" + str(odoend))
print("Miles Driven:" + str(totalmiles))
print("Amount Due:"+"${:,.2f}".format(amtdue))
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per requirement submitted above kindly find below solution.

Here new python program with name "rental.py" is created which contains below code.

rental.py:

import sys #import module
#asking user rental ,upper() function in python used to convert user input to upper case
rentalcode = input("(B)udget, (D)aily, or (W)eekly rental?\n").upper()
if rentalcode == 'B' or rentalcode == 'D': #cheking rental code using if statemnet
#if rental code is B then asking user rented days
rentalperiod = int(input("Number of Days Rented:\n"))
else:
#If rented code is either D or W then asking user weeks rented
rentalperiod = int(input("Number of Weeks Rented:\n"))

# declaring variable to set Pricing
budget_charge = 40.00 #this variable store budget charge
daily_charge = 60.00 #this variable store daly charge
weekly_charge = 190.00 #this variable store weekly charge

#Second Section 2
odostart =int(input("Starting Odometer Reading:\n")) #asking user starting odometer reading
odoend =int(input("Ending Odometer Reading:\n")) #asking user ending odometer reading
#total miles can be found by subtraction odometerending reading from starting reading
totalmiles = int(odoend) - int(odostart)

#checking rentalCode
extramiles=0 #declaring variable
if rentalcode == 'B':#if rentalCode is B then calculate mile charge
milecharge = 0.25 * totalmiles
if rentalcode == "D": #if rentalCode is D then
averagedailymiles = int(totalmiles) /int(rentalperiod) #cakculate daily average miles
if averagedailymiles <= 100: #checking averagedailymiles
totalmiles = 0 #if averagedailymiles is less than or equal to 100 then set totalmiles
elif averagedailymiles > 100: #if averagedailymiles is greater than 100 then
extramiles = averagedailymiles - 100 #calculate extramiles
milecharge = .25 * extramiles #calculate mile charge
if rentalcode == "W" and averagedailymiles > 900: #checking rentalCode and averagedailymiles
milecharge = rentalperiod * 100 #if renatlCode=W and averagedailymiles is gretaer than 900 then calculate mile charge
elif rentalcode == "W" and averagedailymiles <= 900:
milecharge = 0 #if rentalCode is W and averagedailymiles is less than or equal to 0 then calculate mile charge

if rentalcode == "B":#if rentalCode is B then
basecharge = rentalperiod * budget_charge #calculate baseCharge
elif rentalcode == "D":#if rentalCode is D then
basecharge = rentalperiod * daily_charge #calculate baseCharge
elif rentalcode == "W": #if rentalCode is W then
basecharge = rentalperiod * weekly_charge #calculate baseCharge
amtdue = float(basecharge) +float(milecharge) #calculate amount due

print("Rental Summary") #print rental summary details
print("Rental Code:" + str(rentalcode)) #print rental code
print("Rental Period:" + str(rentalperiod)) #print rental period
print("Starting Odometer:" + str(odostart)) #print start odometer reading
print("Ending Odometer:" + str(odoend))#print end odometer reading
print("Miles Driven:" + str(totalmiles))#print total miles
print("Amount Due:"+"${:,.2f}".format(amtdue)) #print amount due

***********************************

Screen for indentation :

==================================

Output :Compile and run rental.py to get the screen as shown below

Screen 1:rental.py , screen for couple of runs

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Code comments explain and facilitate navigation of the code python import sys rentalcode = input("(B)udget, (D)aily,...
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
  • Section 1: Collect customer input ''' rentalCode = input('(B)udget, (D)aily, or (W)eekly rental?\n') if rentalCode ==...

    Section 1: Collect customer input ''' rentalCode = input('(B)udget, (D)aily, or (W)eekly rental?\n') if rentalCode == 'B' or rentalCode == 'D': rentalPeriod = int(input('Number of Days Rented:\n')) else: rentalPeriod = int(input('Number of Weeks Rented:\n')) daysRented = rentalPeriod #Assigning a dollar amount (double floating number) to the varying rates budget_charge = 40.00 daily_charge = 60.00 weekly_charge = 190.00 #baseCharge changes value based on the type of rental code using multiplication #Each branch of if or elif assignes a different value to...

  • what am I missing? this should be the output: (B)udget, (D)aily, or (W)eekly rental? B Starting...

    what am I missing? this should be the output: (B)udget, (D)aily, or (W)eekly rental? B Starting Odometer Reading: Ending Odometer Reading: 1234 2222 988 247.00 my output is this: (B)udget, (D)aily, or (W)eekly rental? Starting Odometer Reading: Ending Odometer Reading: 1234 2222 988 247.00 here's my code so far: import sys ''' Section 1: Collect customer input ''' #Add customer input 1 here, rentalCode = input("(B)udget, (D)aily, or (W)eekly rental?") #Collect Customer Data - Part 2 #4)Collect Mileage information: ##a)...

  • I am completing a rental car project in python. I am having syntax errors returned. currently...

    I am completing a rental car project in python. I am having syntax errors returned. currently on line 47 of my code "averageDayMiles = totalMiles/daysRented" my entire code is as follows: #input variable rentalCode = input("(B)udget , (D)aily , (W)eekly rental? \n") if(rentalCode == "B"): rentalPeriod = int(input("Number of hours rented?\n")) if(rentalCode == "D"): rentalPeriod = int(input("Number of days rented?\n")) if(rentalCode == "W"): rentalPeriod = int(input("Number of weeks rented?\n")) rentalPeriod = daysRented return rentalCode , rentalPeriod budget_charge = 40.00 daily_charge...

  • Calculate the base charge if rentalCode == 'B': baseCharge = rentalPeriod * budgetCharge Set the base...

    Calculate the base charge if rentalCode == 'B': baseCharge = rentalPeriod * budgetCharge Set the base charge for the rental type equal to the variable baseCharge. The base charge is the rental period * the appropriate rate: For example: Finish the conditional statement by adding the conditions for other rental codes. import sys ''' Section 1: Collect customer input ''' # For holding cost of miles drive mileCharge = 0 # Reading type of rental rentalCode = input("(B)udget, (D)aily, or...

  • Propose: In this lab, you will complete a Python program with one partner. This lab will...

    Propose: In this lab, you will complete a Python program with one partner. This lab will help you with the practice modularizing a Python program. Instructions (Ask for guidance if necessary): To speed up the process, follow these steps. Download the ###_###lastnamelab4.py onto your desktop (use your class codes for ### and your last name) Launch Pyscripter and open the .py file from within Pyscripter. The code is already included in a form without any functions. Look it over carefully....

  • python programming: Can you please add comments to describe in detail what the following code does:...

    python programming: Can you please add comments to describe in detail what the following code does: import os,sys,time sl = [] try:    f = open("shopping2.txt","r")    for line in f:        sl.append(line.strip())    f.close() except:    pass def mainScreen():    os.system('cls') # for linux 'clear'    print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")    print(" SHOPPING LIST ")    print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")    print("\n\nYour list contains",len(sl),"items.\n")    print("Please choose from the following options:\n")    print("(a)dd to the list")    print("(d)elete from the list")    print("(v)iew the...

  • Explain what the code is doing line from line explanations please or summarize lines with an explanation def displayCart(): #displays the cart function """displayCart function - dis...

    Explain what the code is doing line from line explanations please or summarize lines with an explanation def displayCart(): #displays the cart function """displayCart function - displays the items in the cart ---------------------------------------------------------------------""" import os os.system('clear') print("\n\nCart Contents:") print("Your selected items:", cart) def catMenu(): #function that displays the category menu """catMenu function - displays the categories user picks from ---------------------------------------------------------------------""" import os os.system('clear') print(""" 1 - Books 2 - Electronics 3 - Clothing d - display cart contents x -...

  • Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk()...

    Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk() self.main.title("mine sweeper") self.define_widgets() self.mines = random.sample( [(i,j) for i in range(25) for j in range(50) ],self.CustomizeNumberOfMines()) print(self.mines) self.main.mainloop() self.CustomizeNumberOfMines() def define_widgets(self): """ Define a canvas object, populate it with squares and possible texts """ self.canvas = tk.Canvas(self.main, width = 1002, height=502, bg="#f0f0f0") self.canvas.grid(row=0, column=0) self.boxes =...

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