A list named parking_tickets has been defined to be the number of parking tickets given out by the city police each day since the beginning of the current year. (Thus, the first element of the list contains the number of tickets given on January 1; the last element contains the number of tickets given today.)

Write some code that associates most_tickets with the largest value found in parking_tickets. You may, if you wish, use one additional variable , k.

Respuesta :

Answer:

The needed code is highlighted from the current text. The rest of the code is for the simplicity purpose and to show the functionality of the logic that is used to find the most of the tickets sold till date.

Please do go through it

Explanation:

# import the required packages

import datetime

import random

# define the parking_tickets

parking_tickets = []

# set the 1'st day of the year in d1

d1 = datetime.datetime(2016,1,1)

# set the current day

d2 = datetime.datetime.now()

# calculate number of days till date

totalDays = (d2-d1).days

# fill the number of tickets sold each day randomly

# into the parking_tickets till date

for i in range(totalDays):

    randValue = random.randint(1, 100)

    parking_tickets.append(randValue)

# print the list of tickets sold in each day

print("The list of tickets sold over starting from January 1 to till day are: \n",parking_tickets)

# the required actual code

# define a variable to hold the most of the tickets sold

most_tickets = 0

# logic to find the tickets that sold the most

for k in range(len(parking_tickets)):

    # condition to check most_tickets value is lesser than

    # parking_tickets at index k(each day)

    if most_tickets < parking_tickets[k]:

         # if it is less than the parking_tickets at index k

         # then set the value to the most_tickets

         most_tickets = parking_tickets[k]

# print the most tickets sold

print("Most of the tickets that are sold with in date is ", most_tickets)