Luka got a job driving trucks. One evening he parked his three trucks in a rest area which charges for parking in an unusual way – they give a discount on quantity. When only one truck is parked, the driver pays A dollars per minute. When two trucks are parked, the drivers each pay B dollars per minute. When three trucks are parked, the drivers each pay C dollars per minute. Given the numbers A, B and C, as well as the intervals in which Luka’s three trucks are parked, determine how much Luka needs to pay the owner of the rest area. The first line of input contains three integers A, B and C (1≤C≤B≤A), the prices of parking as defined above. Each of the following three lines contains two integers each. These are the arrival and departure times (in minutes) of one of Luka’s trucks. The arrival time will always be earlier than the departure time. The rest area charges for the last minute, so the starting and ending times are inclusive. Output the overall cost of parking Luka's three trucks.   Template def get_input(): a, b, c = input().split(" ") s1, e1 = input().split(" ") # TODO: Finish here. # Convert the data types to integers # and return the values properly a = int(a) # TODO: Finish here. # TODO: Make sure you have variables a, b, c, which are the fees # and make sure you have three tuples: t1, t2, t3 which are (starting minute, ending minute). return a, b, c, t1, t2, t3 def calculate(a, b, c, t1, t2, t3): # t1 is a tuple for truck 1 # t2 is a tuple for truck 2 # t3 is a tuple for truck 3 # t1[0] is the start time for truck 1 # t1[1] is the end time for truck 1 # We can create a time range using range() # built-in function. We need t1[1]+1 because # the end is exclusive, not inclusive. truck1 = range(t1[0], t1[1]+1) # TODO: Do the same for truck 2 and 3 # We need to know the first starting point # which is the minimum of t1[0], t2[0], and t3[0] start_time = min(t1[0], t2[0], t3[0]) # We also need to know the last ending point # TODO: Finish here. # Now you need to loop through each time from # start_time to end_time and see if truck 1, 2, or 3 # are there. Make a variable that keeps track of the # number of trucks. total_cost = 0 for tm in range(start_time, end_time + 1): if tm in truck1: # TODO: Keep track that truck 1 was here for this minute. # TODO: Do the same for truck2 and truck 3. # When we count the number of trucks there for this minute # TODO: # add a to the cost if there is only one truck # add b to the cost for each truck if there are two trucks # add c to the cost for each truck if there are three trucks # add nothing to the cost if there are NO trucks # Make sure you use the variable "total_cost". Below will return # that data back to the main function. return total_cost if __name__ == "__main__": a, b, c, t1, t2, t3 = get_input() total_cost = calculate(a, b, c, t1, t2, t3) print(total_cost) Assignment Step 1 Create a function called get_input(). Retrieve the values of A, B, C on the first line and convert them into integers. Retrieve the start and end times of the first truck on the next line. Retrieve the start and end times of the second truck on the next line. Retrieve the start and end times of the third truck on the next line. Convert the dollar types so that A, B, and C are integers. Convert the truck times as tuples of the start and end times. For example t1 = (truck1_start, truck1_end). Recall that tuples are just like lists, except they are created with () and they are read only. Return A, B, C, truck1, truck2, and truck3. All six pieces of information must be returned at once. Recall that you can return multiple variables by separating them with commas, like return a, b, c, t1, t2, t3. Step 2 Write a function called calculate(). The function will take six parameters: a, b, c, t1, t2, t3. a, b, and c are the dollar amounts A, B, and C, respectively. t1, t2, t3, are tuples containing the start and end times of each truck, t1, t2, t3, respectively. Expand t1, t2, and t3 into their respective ranges. Notice that t1, t2, and t3 are just the start and end times, but you need to fill in the times in between using range(). Find the first minute a truck arrives and the last minute a truck leaves. This is the total time range you need to consider when counting trucks. Times outside of this range have no trucks at the parking lot. Take note that a, b, and c are dollar amounts for ONE truck only. You need to scale this depending on how many trucks are at the lot simultaneously. Calculate the total cost of all trucks and return that value. Step 3 Write your testing apparatus. if __name__ == "__main__": a, b, c, t1, t2, t3 = get_input() total_cost = calculate(a, b, c, t1, t2, t3) print(total_cost) The if __name__ portion is absolutely essential in your submission. We will be testing your code by running pieces of your code. Testing Given input: 5 3 1 1 6 3 5 2 8 output should be 36

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Luka got a job driving trucks. One evening he parked his three trucks in a rest area which charges for parking in an unusual way – they give a discount on quantity.

When only one truck is parked, the driver pays A dollars per minute. When two trucks are parked, the drivers each pay B dollars per minute. When three trucks are parked, the drivers each pay C dollars per minute.

Given the numbers A, B and C, as well as the intervals in which Luka’s three trucks are parked, determine how much Luka needs to pay the owner of the rest area.

The first line of input contains three integers A, B and C (1≤C≤B≤A), the prices of parking as defined above. Each of the following three lines contains two integers each. These are the arrival and departure times (in minutes) of one of Luka’s trucks. The arrival time will always be earlier than the departure time. The rest area charges for the last minute, so the starting and ending times are inclusive.

Output the overall cost of parking Luka's three trucks.

 

Template

def get_input(): a, b, c = input().split(" ") s1, e1 = input().split(" ")
# TODO: Finish here. # Convert the data types to integers
# and return the values properly
a = int(a)
# TODO: Finish here.

# TODO: Make sure you have variables a, b, c, which are the fees
# and make sure you have three tuples: t1, t2, t3 which are (starting minute, ending minute).
return a, b, c, t1, t2, t3

def calculate(a, b, c, t1, t2, t3):
# t1 is a tuple for truck 1
# t2 is a tuple for truck 2
# t3 is a tuple for truck 3
# t1[0] is the start time for truck 1
# t1[1] is the end time for truck 1
# We can create a time range using range()
# built-in function. We need t1[1]+1 because
# the end is exclusive, not inclusive.
truck1 = range(t1[0], t1[1]+1)
# TODO: Do the same for truck 2 and 3

# We need to know the first starting point
# which is the minimum of t1[0], t2[0], and t3[0]
start_time = min(t1[0], t2[0], t3[0])
# We also need to know the last ending point
# TODO: Finish here.

# Now you need to loop through each time from
# start_time to end_time and see if truck 1, 2, or 3
# are there. Make a variable that keeps track of the
# number of trucks.
total_cost = 0
for tm in range(start_time, end_time + 1):
if tm in truck1:
# TODO: Keep track that truck 1 was here for this minute.
# TODO: Do the same for truck2 and truck 3.
# When we count the number of trucks there for this minute
# TODO:
# add a to the cost if there is only one truck
# add b to the cost for each truck if there are two trucks
# add c to the cost for each truck if there are three trucks
# add nothing to the cost if there are NO trucks
# Make sure you use the variable "total_cost". Below will return
# that data back to the main function.
return total_cost

if __name__ == "__main__":
a, b, c, t1, t2, t3 = get_input()
total_cost = calculate(a, b, c, t1, t2, t3)
print(total_cost)

Assignment

Step 1

  • Create a function called get_input().
  • Retrieve the values of A, B, C on the first line and convert them into integers.
  • Retrieve the start and end times of the first truck on the next line.
  • Retrieve the start and end times of the second truck on the next line.
  • Retrieve the start and end times of the third truck on the next line.
  • Convert the dollar types so that A, B, and C are integers.
  • Convert the truck times as tuples of the start and end times. For example t1 = (truck1_start, truck1_end).
  • Recall that tuples are just like lists, except they are created with () and they are read only.
  • Return A, B, C, truck1, truck2, and truck3. All six pieces of information must be returned at once. Recall that you can return multiple variables by separating them with commas, like return a, b, c, t1, t2, t3.

Step 2

Write a function called calculate().

  • The function will take six parameters: a, b, c, t1, t2, t3.
  • a, b, and c are the dollar amounts A, B, and C, respectively.
  • t1, t2, t3, are tuples containing the start and end times of each truck, t1, t2, t3, respectively.
  • Expand t1, t2, and t3 into their respective ranges. Notice that t1, t2, and t3 are just the start and end times, but you need to fill in the times in between using range().
  • Find the first minute a truck arrives and the last minute a truck leaves. This is the total time range you need to consider when counting trucks. Times outside of this range have no trucks at the parking lot.
  • Take note that a, b, and c are dollar amounts for ONE truck only. You need to scale this depending on how many trucks are at the lot simultaneously.
  • Calculate the total cost of all trucks and return that value.

Step 3

Write your testing apparatus.

if __name__ == "__main__":
a, b, c, t1, t2, t3 = get_input()
total_cost = calculate(a, b, c, t1, t2, t3)
print(total_cost)

The if __name__ portion is absolutely essential in your submission. We will be testing your code by running pieces of your code.

Testing

Given input:

5 3 1 1 6 3 5 2 8

output should be

36

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY