Question

In: Computer Science

Project #2 ## Language Should be Python. Using for, while, if, elif only. No advanced functions....

Project #2

## Language Should be Python. Using for, while, if, elif only. No advanced functions.

Assignment Specifications

The program will compute and display information for a company which rents vehicles to its customers. For a specified customer, the program will compute and display the amount of money charged for that customer’s vehicle rental.

  1. The program should start by asking the user if he wants to continue. The answer is ‘Y’ for yes or ‘N’ for no.

The basic structure of the main loop is

Prompt to see if the user wants to continue

While the value is ‘Y’:

All your other code goes here

Prompt to see if the user wants to continue

  1. It will then continue to prompt the user to enter the following four items for a given customer (in the specified order):
    1. The customer's classification code (a character)
    1. The number of days the vehicle was rented (an integer)
    1. The vehicle's odometer reading at the start of the rental period (an integer)
    1. The vehicle's odometer reading at the end of the rental period (an integer)

It will then process that customer information and display the results. At the end, the program should ask the user if he wants to process another request and it will keep asking until the user enter 0.

  1. The program will compute the amount of money that the customer will be billed, based on the customer's classification code, number of days in the rental period, and number of miles driven. The program will recognize both upper case and lower case letters for the classification codes.

Code 'B' (budget)

base charge: $40.00 for each day

mileage charge: $0.25 for each mile driven

Code 'D' (daily)

base charge: $60.00 for each day

mileage charge: no charge if the average number of miles driven per day is 100 miles or less; otherwise, $0.25 for each mile driven above the 100 mile per day limit.

Code 'W' (weekly)

base charge: $190.00 for each week (or fraction of a week)

mileage charge: no charge if the average number of miles driven per week is 900 miles or less; $100.00 per week if the average number of miles driven per week exceeds 900 miles but does not exceed 1500 miles; otherwise, $200.00 per week plus $0.25 for each mile driven above the 1500 mile per week limit.

The amount billed to the customer is the sum of the base charge and the mileage charge.

  1. The program will compute the number of miles driven by the customer during the rental period. The odometer readings are taken from an odometer which has six digits and records tenths of a mile.
  2. For each customer, the program will display a summary with the following information:
    1. The customer's classification code
    1. The number of days the vehicle was rented
    1. The vehicle's odometer reading at the start of the rental period
    1. The vehicle's odometer reading at the end of the rental period
    1. The number of miles driven during the rental period
    1. The amount of money billed to the customer for the rental period

All output will be appropriately labeled and formatted. The number of miles driven will be rounded to one fractional digit. The amount of money billed will be displayed with a dollar sign and will be rounded to two fractional digits (for example, $125.99 or $43.87). Note that we do not have the ability yet to fine tune the output so if cents end in zero that final zero will not be

displayed—that is fine for this project. We provide a file strings.txt with the strings we used to make it easier for you to match our output.

  1. The program will detect, report and recover from invalid classification codes. When an invalid classification code is detected, the program will display an error message and re-prompt until a correct classification code is entered.

Hint: use a while loop that will loop until a correct classification code is entered. Here is pseudo code of that loop:

Prompt for a value

While the value is not correct:

Print an error message

Prompt for a value

  1. The program will assume that all other user inputs are valid and correct. That is, the program will not check the number of days or odometer readings for validity. However, as noted below you may encounter an ending odometer reading that is less than the beginning reading and you need to handle that correctly.

Assignment Notes

  1. As stated above, the odometer's dial has six digits and records tenths of a mile. For example, if the beginning reading was 100003 and the ending reading was 100135, then the customer drove 13.2 miles during the rental period.
  2. Since the odometer’s dial is fixed with only six digits, the reading at the end of the rental period may be less than the reading at the beginning of the billing period. For example, if the beginning reading was 999997 and the ending reading was 000005, then the customer drove 0.8 miles during the rental period. You need to handle that arithmetic correctly.

Test 1

Welcome to car rentals.

At the prompts, please enter the following:

Customer's classification code (a character: BDW)

Number of days the vehicle was rented (int)

Odometer reading at the start of the rental period (int)

Odometer reading at the end of the rental period (int)

Would you like to continue (Y/N)? N

Thank you for your loyalty.

Test 2

Welcome to car rentals.

At the prompts, please enter the following:

Customer's classification code (a character: BDW)

Number of days the vehicle was rented (int)

Odometer reading at the start of the rental period (int)

Odometer reading at the end of the rental period (int)

Would you like to continue (Y/N)? Y

Customer code (BDW): D

Number of days: 1

Odometer reading at the start: 100003

Odometer reading at the end:      100135

Customer summary:

classification code: D

rental period (days): 1

odometer reading at start: 100003

odometer reading at end:      100135

number of miles driven:    13.2

amount due: $ 60.0

Would you like to continue (Y/N)? Y

Customer code (BDW): D

Number of days: 4

Odometer reading at the start: 101010

Odometer reading at the end:      108200

Customer summary:

classification code: D

rental period (days): 4

odometer reading at start: 101010

odometer reading at end:      108200

number of miles driven:    719.0

amount due: $ 319.75

Would you like to continue (Y/N)? Y

Customer code (BDW): D

Number of days: 2

Odometer reading at the start: 002000

Odometer reading at the end:      004000

Customer summary:

classification code: D

rental period (days): 2

odometer reading at start: 2000

odometer reading at end:      4000

number of miles driven:    200.0

amount due: $ 120.0

Would you like to continue (Y/N)? Y

Customer code (BDW): B

Number of days: 3

Odometer reading at the start: 999997

Odometer reading at the end:      000005

Customer summary:

classification code: B

rental period (days): 3

odometer reading at start: 999997

odometer reading at end:      5

number of miles driven: 0.8

amount due: $ 120.2

Would you like to continue (Y/N)? N

Thank you for your loyalty.

Test 5

Welcome to car rentals.

At the prompts, please enter the following:

Customer's classification code (a character: BDW)

Number of days the vehicle was rented (int)

Odometer reading at the start of the rental period (int)

Odometer reading at the end of the rental period (int)

Would you like to continue (Y/N)? Y

Customer code (BDW): x

*** Invalid customer code. Try again. ***

Customer code (BDW): y

*** Invalid customer code. Try again. ***

Solutions

Expert Solution

Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

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

def compute_bill(code,days,start_reading,end_reading):
    distance=getDistance(start_reading,end_reading)
    if code=='B':
        return 40*days + (distance)*0.25
    elif code=='D':
        average= (distance)/days
        if average<=100:
            return 60*days
        else:
            print(distance)
            return 60*days+ 0.25*(distance-days*100)
    elif code=='W':
        average_weekly=(distance)*7/days
        if average_weekly<=900:
            return 190*(days)/7
        elif average_weekly<=1500:
            return 100*(days)/7
        else:
            return 200*days/7 + (average_weekly-1500)*0.25
    else:
        return 0

def getDistance(start_reading,end_reading):
    if start_reading > end_reading:
        distance = (1+(999999 - start_reading) + end_reading) / 10.0
    else:
        distance = end_reading - start_reading
    distance /= 10.0
    return distance


def printInstructions():
    print('Welcome to car rentals.')
    print('At the prompts, please enter the following:')
    print('Customer\'s classification code (a character: BDW)')
    print('Number of days the vehicle was rented (int)')
    print('Odometer reading at the start of the rental period (int)')
    print('Odometer reading at the end of the rental period (int)')
def main():
    #printInstructions()
    while True:
        answer=input('Would you like to continue (Y/N)? ')
        if answer=='Y':
            while True:
                code = input('Customer code (BDW): ').upper()
                if code not in ['B','D','W']:
                    print('*** Invalid customer code. Try again. ***')
                else:
                    break
                
            days=int(input("Number of days: "))
            start_reading=int(input('Odometer reading at the start: '))
            end_reading=int(input('Odometer reading at the end: '))
            bill=compute_bill(code,days,start_reading,end_reading)
            print('Customer summary:')
            print('classification code: {}'.format(code))
            print('rental period (days): {}'.format(days))
            print('odometer reading at start:  {}'.format(start_reading))
            print('odometer reading at end:     {}'.format(end_reading))
            print('number of miles driven:      {}'.format(getDistance(start_reading,end_reading)))
            print('amount due: $ {0:.2f}'.format(bill))
        else:
            print('Thank you for your loyalty.')
            break
main()

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


Related Solutions

Programming language Python It have to be in Functions with a main function Samuel is a...
Programming language Python It have to be in Functions with a main function Samuel is a math teacher at Hogwarts School of Witchcraft and Wizardry. He loves to give his students multiplication exercises. However, he doesn’t care about the actual operation result but the unit sum of its digits. At Hogwarts School of Witchcraft and Wizardry, they define the unit sum (US) of N as the unit that it is left after doing the sum of all the digits of...
Write an example of a Python while loop that is infinite, calls the functions first(), second()...
Write an example of a Python while loop that is infinite, calls the functions first(), second() and third() in that order in the body of the loop, but skips calling second() and third() if first() returns a value of False, and exits if second() returns a value of False. Declare a Python function named sumEm() that accepts three numeric parameters and returns the sum of the three numbers. Assume sumEm() is declared in a module named myMod.py, which your program...
Python - Rewriting a Program Rewrite Program 1 using functions. The required functions are in the...
Python - Rewriting a Program Rewrite Program 1 using functions. The required functions are in the table below. Create a Python program that will calculate the user’s net pay based on the tax bracket he/she is in. Your program will prompt the user for their first name, last name, their monthly gross pay, and the number of dependents. The number of dependents will determine which tax bracket the user ends up in. The tax bracket is as follows: 0 –...
Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
Programming language is in python 3 For this project, you will import the json module. Write...
Programming language is in python 3 For this project, you will import the json module. Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as parameters a...
Programming language is python 3 For this project, you will import the json module. Write a...
Programming language is python 3 For this project, you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The...
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and use a function named highest() that takes three inputs and returns the highest number. After you have got it working, try calling the function with inputs ‘hat’, ‘cat’, ‘rat’.
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd Binary numbers // 00000000, 0101, 111111, etc. Show: Finite Automaton Definition, Graph, Table
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT