Question

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):

  1. To speed up the process, follow these steps.
    1. Download the ###_###lastnamelab4.py onto your desktop (use your class codes for ### and your last name)
    2. Launch Pyscripter and open the .py file from within Pyscripter.
    3. The code is already included in a form without any functions. Look it over carefully. You will convert it and use functions to accomplish each tasks.

  1. Add your class codes and names to the comments at the top as following:

#Name : ###YourLastName

#Name : ###YourLastName

  1. This Python program will complete the following program description

   You are asked to modify a program to calculate the cost of renting a vehicle. The user will input the type of rental, the days rented, the mileage driven and their preferred customer status. I want you to evaluate the code for the detail and ask any questions at the start of the lab. It is a good idea to look at all the details and place a checkmark by anything you don’t understand. Your next project will have some of these qualities.

  1. Rewrite the code:                                                                                                  
  1. At the top of the file I have declared some SYMBOLIC values. Theses are our global constants. We don’t pass these globals because they will be accessible in your functions.
  2. The modified version of your program will contain a main function similar to the exercises we completed in class.

Here is the algorithm for the main function

Input rentalCode

            Input numDays

            Input numMiles

            Input prefCust

            call getRentalStr - 1 argument needed, 1 return

            call getRentalCost - 2 arguments needed, 1 return

            call getMileCost -   2 arguments needed, 1 return

            call getPrefDisc – 3 arguments needed, 1 return

            calc finalCost = rentalCost + mileCost - prefDisc

            print output

  1. Once you complete the call statements, copy/paste the code into its own function with the appropriate parameters and return statements when needed.
  2. Run your code with the following input

Rental Type           Days                Miles            Preferred

  1. C                     5                      750                  Y
  2. W                    10                    750 N
  3. S                      1                      200                  Y

Here is the code given:

# leave these as global constant initialized values
#GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
WREC_PRICE = 15.00
ECON_PRICE = 25.00
COMP_PRICE = 30.00
SUV_PRICE = 60.00
PER_MILES = 0.25
PREF_DISC = 0.15
#GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG

#==================================================================
#======================== Start of the main function ==============
def main():
    #input
    rentaltype = input("Enter the letter code\nW - Wreck\nE - Economy\nC - Compact\nS - SUV\n: ")
    numDays = int(input("Enter the number of days rented: "))
    numMiles = int(input("Enter the number of miles driven: "))
    prefCust = input("Are you a preferred customer enter Y or N: ")



    #-------------------------------------------------------
    # convert this into a function called getRentalStr
    #-------------------------------------------------------
    if rentaltype == "W" or rentaltype == "w":
        rentaltype = "Wreck"
    elif rentaltype == "E" or rentaltype == "e":
        rentaltype = "Economy"
    elif rentaltype == "C" or rentaltype == "c":
        rentaltype = "Compact"
    elif rentaltype == "S" or rentaltype == "s":
        rentaltype = "SUV"
    #-------------------------------------------------------


    #-------------------------------------------------------
    # convert this into a function called getRentalCost
    #-------------------------------------------------------
    if rentaltype == "Wreck":
        rentalRate =  WREC_PRICE
    elif rentaltype == "Economy":
        rentalRate =  ECON_PRICE
    elif rentaltype == "Compact":
        rentalRate =  COMP_PRICE
    elif rentaltype == "SUV":
        rentalRate =  SUV_PRICE
    rentalCost = rentalRate *  numDays
    #-------------------------------------------------------


    #-------------------------------------------------------
    # convert this into a function called getMileCost
    #-------------------------------------------------------
    excessMiles = numMiles - numDays * 100
    if excessMiles > 0:
        mileCost = excessMiles * PER_MILES
    else:
        mileCost = 0
    #-------------------------------------------------------

    #-------------------------------------------------------
    # convert this into a function called getPrefDisc
    #-------------------------------------------------------
    if prefCust == "Y" or prefCust == "y":
        prefDisc = (rentalCost + mileCost) * PREF_DISC
    else:
        prefDisc = 0
    #-------------------------------------------------------


    finalCost = rentalCost +  mileCost -  prefDisc



    print ("======= Falcon Rentals ==========")
    print ("Rental Type:", rentaltype)
    print ("Days Rented:", numDays)
    print ("Rental Cost     $", format(rentalCost, "7.2f"))
    print ("Mileage Cost    $", format(mileCost, "7.2f"))
    print ("Preferred Disc  $", format(-prefDisc, "7.2f"))
    print ("Final Cost      $", format(finalCost, "7.2f"))
    print ("=================================")

    #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
main()
input()
# end
0 0
Add a comment Improve this question Transcribed image text
Answer #1
# leave these as global constant initialized values
#GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
WREC_PRICE = 15.00
ECON_PRICE = 25.00
COMP_PRICE = 30.00
SUV_PRICE = 60.00
PER_MILES = 0.25
PREF_DISC = 0.15
#GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG


def getRentalStr(rentaltype):
    if rentaltype == "W" or rentaltype == "w":
        rentaltype = "Wreck"
    elif rentaltype == "E" or rentaltype == "e":
        rentaltype = "Economy"
    elif rentaltype == "C" or rentaltype == "c":
        rentaltype = "Compact"
    elif rentaltype == "S" or rentaltype == "s":
        rentaltype = "SUV"
    return rentaltype

def getRentalCost(rentaltype,numDays):
    if rentaltype == "Wreck":
        rentalRate =  WREC_PRICE
    elif rentaltype == "Economy":
        rentalRate =  ECON_PRICE
    elif rentaltype == "Compact":
        rentalRate =  COMP_PRICE
    elif rentaltype == "SUV":
        rentalRate =  SUV_PRICE
    rentalCost = rentalRate *  numDays
    return rentalCost

def getMileCost(numMiles,numDays):
    excessMiles = numMiles - numDays * 100
    if excessMiles > 0:
        mileCost = excessMiles * PER_MILES
    else:
        mileCost = 0
    return mileCost
def getPrefDisc(prefCust,rentalCost,mileCost):
    if prefCust == "Y" or prefCust == "y":
        prefDisc = (rentalCost + mileCost) * PREF_DISC
    else:
        prefDisc = 0
    return prefDisc
#==================================================================
#======================== Start of the main function ==============
def main():
    #input
    rentaltype = input("Enter the letter code\nW - Wreck\nE - Economy\nC - Compact\nS - SUV\n: ")
    numDays = int(input("Enter the number of days rented: "))
    numMiles = int(input("Enter the number of miles driven: "))
    prefCust = input("Are you a preferred customer enter Y or N: ")



    #-------------------------------------------------------
    # convert this into a function called getRentalStr
    #-------------------------------------------------------
    rentaltype=getRentalStr(rentaltype)
    #-------------------------------------------------------


    #-------------------------------------------------------
    # convert this into a function called getRentalCost
    #-------------------------------------------------------
    rentalCost = getRentalCost(rentaltype,numDays)
    #-------------------------------------------------------


    #-------------------------------------------------------
    # convert this into a function called getMileCost
    #-------------------------------------------------------
    mileCost=getMileCost(numMiles,numDays)
    #-------------------------------------------------------

    #-------------------------------------------------------
    # convert this into a function called getPrefDisc
    #-------------------------------------------------------
    prefDisc=getPrefDisc(prefCust,rentalCost,mileCost)
    #-------------------------------------------------------


    finalCost = rentalCost +  mileCost -  prefDisc



    print ("======= Falcon Rentals ==========")
    print ("Rental Type:", rentaltype)
    print ("Days Rented:", numDays)
    print ("Rental Cost     $", format(rentalCost, "7.2f"))
    print ("Mileage Cost    $", format(mileCost, "7.2f"))
    print ("Preferred Disc  $", format(-prefDisc, "7.2f"))
    print ("Final Cost      $", format(finalCost, "7.2f"))
    print ("=================================")

    #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
main()
input()
# end
Add a comment
Know the answer?
Add Answer to:
Propose: In this lab, you will complete a Python program with one partner. This lab will...
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
  • In this question you have to write a C++ program to convert a date from one...

    In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of a main() function and a function called convertDate(). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received, the string that the function...

  • 1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write...

    1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x):     if x in "aeiouyAEIOUY":         return True     else:...

  • QUESTION 6 15 marks In this question you have to write a C++ program to convert...

    QUESTION 6 15 marks In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of amain () function and a function called convertDate(). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received, the...

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

  • 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":...

  • 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...

  • Write a Python program to create userids: You work for a small company that keeps the...

    Write a Python program to create userids: You work for a small company that keeps the following information about its clients: • first name • last name • a user code assigned by your company. The information is stored in a file clients.txt with the information for each client on one line (last name first), with commas between the parts. In the clients.txt file is: Jones, Sally,00345 Lin,Nenya,00548 Fule,A,00000 Your job is to create a program assign usernames for a...

  • This is a python question. from urllib import request import json """ Complete this program that...

    This is a python question. from urllib import request import json """ Complete this program that calculates conversions between US dollars and other currencies. In your main function, start a loop. In the loop, ask the user what currency code they would like to convert to And, how many dollars they want to convert. If you scroll down, you can see an example response with the available 3-letter currency codes. Call the get_exchange_rates() function. This function returns a dictionary with...

  • QUESTION 6 15 marks In this question you have to write a C++ program to convert...

    QUESTION 6 15 marks In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of a main() function and a function called convertDate(). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received, the...

  • Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing an...

    Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing and catching exceptions in this exercise. Create a file called RuntimeException.h and put the following code in it. #include <string> class RuntimeException { private: string errorMsg; public: RuntimeException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } } Step Two In a new .cpp file in your directory, write a main function...

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