Question

In: Computer Science

You want to write a simple python program for a food delivery company that asks the...

You want to write a simple python program for a food delivery company that asks the office worker how many drivers they require to deliver their packages to different parts of town. When the user enters the number of drivers, the program will ask how many packages each driver will carry to its destination. It will then calculate the total number of packages and display the result on the screen as below.

Sample run: How many drivers do you need? 5

Packages for driver 1: 3

Packages for driver 2: 4

Packages for driver 3: 1

Packages for driver 4: 12

Packages for driver 5: 8

5 drivers delivered a total of 28 packages.

note: please do not use (break) or directories

Solutions

Expert Solution

Solution: We can resolve this problem by making use of python dictionaries. Have given the code below with output. Comments have been placed in the program to depict the functionality.

Hope that helps.

if __name__ == "__main__":

    #Welcome Message 
    print("*** Welcome to the Company ***\n")
    # Ask user for number of drivers
    num_driver = int(input("How many drivers are required: "))

    # Create an empty dictionary
    driver_package = {}

    # Create a variable to store the total packages
    total_package = 0

    # Add drivers and package information to the dictionary
    for i in range(num_driver):
        num_delivery = int(input(f"Packages for Driver {i+1} : "))
        driver_package[i+1] = num_delivery


    #Calculate the total packages
    for i in driver_package.values():
        total_package = total_package + i

    print(f"\n{num_driver} drivers delivered a total of {total_package} packages.")
    print("\n** Thank You **")


Output:

*** Welcome to the Company ***

How many drivers are required: 8
Packages for Driver 1 : 10
Packages for Driver 2 : 20
Packages for Driver 3 : 15
Packages for Driver 4 : 15
Packages for Driver 5 : 30
Packages for Driver 6 : 40
Packages for Driver 7 : 10
Packages for Driver 8 : 25

8 drivers delivered a total of 165 packages.

** Thank You **


Related Solutions

Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT