+1 (315) 557-6473 

Python Program to Implement Password Generation System Assignment Solution.


Instructions

Objective
Write a program to implement password generation system in python.

Requirements and Specifications

This is an individual assignment.
You should avoid using built-in functions of Python, unless clearly stated otherwise.
Answer all the following questions in a single text file (word or pdf) and in two python files (.py - Python 3.6 or newer), one for Question 2 and one for Question 3.
Question 1 (20 marks):
Debug the following code that asks the user to create a new password and if it is not strong enough it produces a random password suggestion.
  • Locate only 3 of the bugs that are within the code, by indicating the line.
  • Provide the correct code for each line where a bug is found.
  • Briefly describe the methodology that allowed you to locate each one of the bugs (max. 200 words).
Code with bugs (Note: Use the exact indentation as shown here to avoid including more bugs. A Python file is attached to avoid any mistakes in copying the code):
Question 2 (50 marks):
You are working for a firm that owns fast-food chain restaurants and plans to open a drive-through on a new location. However, in the process of designing the drive-through (deciding the amount of kitchen staff, locating the estate, and providing the engineers with the area requirements of the building and utilities), your boss asks you to run a set of simulations that will inform the firm of the average time needed for each ticket to be prepared by the kitchen, thus the wait time of each car.
Your boss provides you with a .csv file (find attached) with data from 3 other drive-throughs. It contains the licence plates of cars that have visited the drive-throughs within a time frame of one hour and their orders. You can consider that the data provided are representative for the inflow of cars expected per one hour in the new location and for the number range of items each order usually has. You may hypothesize that the orders will fall into that range with equal probabilities. (You can use built-in functions in Python to extract data from the .csv file and calculate statistical measures -like the average and the range of values- or you can extract the information you need in other ways -excel functions, pen and paper- but describe the method followed.)
A kitchen in the restaurant with 4 members of staff can deliver an average of 9 items of the menu within 10 minutes, while with 6 members of staff it can deliver an average of 16 items of the menu within 10 minutes. Take into account that the rate of producing menu items is only depending on the amount of members of staff (does not matter what items are ordered and no preparation occurs).
You should design a simulation of the drive-through operating for 8 hours that will provide the average waiting time for each of the cars. Use random numbers and run multiple executions (i.e. 10 instances) of the same set-up to extract a more robust prediction.
  1. Design your algorithm by providing pseudocode or diagrams that explain in appropriate level of detail the steps followed.
  2. Write Python code to tackle the aforementioned problem and use it to provide the outputs (that you should include in the text file deliverable) for a kitchen with 4 members of staff and with 6 members. What is your conclusion based on the waiting times?
  3. It would be faster to run one or two simulations of each kitchen set up. Why do you need to run multiple simulations? What is the risk of running one simulation per kitchen set up? Also, explain the choice of data structures and algorithms for your code. 50words.
Question 3 (30 marks):
Create an array (a list of lists) with random integer values and dimensions 100x100. Write an algorithm to sort each row of the array with ascending order for the odd indexed rows and descending order for the even indexed rows.
  • Design your algorithm by providing pseudocode or diagrams that explain in appropriate level of detail the steps followed.
  • Write Python code (do not use built-in functions – you should use algorithms you learnt in practicals) to tackle the aforementioned problem with the following additional constrains:
    1. Use one sorting algorithm based on brute-force strategy to sort the whole array and test the running time for 10 instances of random arrays.
    2. Use another sorting algorithm with different complexity from the previous one to sort the whole array and test the running time for 10 instances of random arrays.

Source Code

QUESTION 1

import random

import pandas as pd

import numpy as np

from zmq import RATE

if __name__ == '__main__':

# Read xlsx

data = pd.read_excel('car_orders.xlsx', skiprows=1)

data = data.fillna(0)

print(data.head())

# Convert to numpy

data = data.to_numpy()

# Store the code of each drivethru

drivethru_codes = data[:,0]

data = data[:,2:]

# Define the step size. In this case, we will simulate with a stepsize of 1 minute

STEP = 1

# Define simulation time in minutes

SIM_TIME = 8*60 # 8 hours

# Define the number of items that can be delivered each 10 minutes

STAFF_MEMBERS = 6

RATE_OF_PRODUCTION = 16 # for 4 staff members

PRODUCTION_TIME = 10 # 10 minutes

# Define the number of instances

INSTANCES = 10

# Dictionary to store the average waiting times for each drive-thru

avg_time = dict()

number_clients = dict()

for i in range(INSTANCES):

#print(f"Running Instance {i+1}...")

# Define dictionaries to store the average time for each instance

instance_avg_time = dict()

instance_number_clients = dict()

# Simulate

time = 0

while time < SIM_TIME:

# Pick a random client

index = np.random.choice(data.shape[0], 1)

client = data[index, :]

# Number of items in client's order

order_items = np.sum(client)

# Compute the total number of minutes this order will take

order_time = order_items*PRODUCTION_TIME/RATE_OF_PRODUCTION

# Get code of drivethru

code = drivethru_codes[index][0]

# Now, add the average waiting time

instance_avg_time[code] = instance_avg_time.get(code, 0) + order_time

instance_number_clients[code] = instance_number_clients.get(code, 0) + 1

time = time + STEP

# Now, compute avg

instance_avg_time = {x: y/instance_number_clients[x] for x, y in instance_avg_time.items()}

# Add to avg_time

for key, val in instance_avg_time.items():

avg_time[key] = avg_time.get(key, 0) + val

# Now compute the final avg time

avg_time = {x: y/INSTANCES for x,y in avg_time.items()}

# Display results

print()

print(f"The average waiting time at each window given {STAFF_MEMBERS} staff members are:")

print("{:<10s} {:>10s}".format("Window", "Avg. Time (min)"))

print("{:<10s} {:>10s}".format("---------", "---------------"))

for key, val in avg_time.items():

print("{:<10s} {:>10.2f}".format(key, val))

print()

QUESTION 2

import random

import time

# Define a function to sort a row of integers

# This function will apply the Merge Sort algorithm since

# That algorithm has a time complexity of nlog(n) which is the faster

def sort(arr, ascending = False):

if len(arr) > 1:

N = len(arr) # size of list

# Compute mid index

mid = N//2

# Take left part

L = arr[:mid]

# Take right part

R = arr[mid:]

# Sort left part

sort(L, ascending)

# Sort right part

sort(R, ascending)

i = j = k = 0

while i < len(L) and j < len(R):

if ascending:

if L[i] <= R[j]: # The part in the left is smaller, so we need to swap

arr[k] = L[i]

i += 1

else:

arr[k] = R[j]

j += 1

else:

if L[i] >= R[j]: # The part in the left is smaller, so we need to swap

arr[k] = L[i]

i += 1

else:

arr[k] = R[j]

j += 1

k += 1

while i < len(L):

arr[k] = L[i]

i += 1

k += 1

while j < len(R):

arr[k] = R[j]

j += 1

k += 1

# Define a function that sorts the algorithm by brute force

def bruteSort(arr, ascending = False):

# Take the size of the array

N = len(arr)

# Now sort

for i in range(N):

for j in range(i+1, N):

; if ascending:

if arr[i] > arr[j]:

arr[i], arr[j] = arr[j], arr[i] # swap

else:

if arr[i] < arr[j]:

arr[i], arr[j] = arr[j], arr[i]

if __name__ == '__main__':

# Define size

N = 100

# Create array

vals_range = range(1,N+1) # 1 and 10

# Define number of instances

INSTANCES = 10

# Declare variables to store the average time for each sorting algorithm

time1 = 0

time2 = 0

# Now generate arrays and sort them to measure their execution times

for inst in range(INSTANCES):

array = [random.sample(vals_range, N) for _ in range(N)]

# Now, sort each row

startTime = time.time()

for i in range(N):

row = array[i]

if i%2 == 0: # Row index is even: Sort descending

sort(row)

else: # Sort ascending

sort(row, True)

array[i] = row

endTime = time.time()

time1 += (endTime - startTime)

# Now for the second sorting algo

array = [random.sample(vals_range, N) for _ in range(N)]

# Now, sort each row

startTime = time.time()

for i in range(N):

row = array[i]

if i%2 == 0: # Row index is even: Sort descending

bruteSort(row)

else: # Sort ascending

bruteSort(row, True)

array[i] = row

endTime = time.time()

time2 += (endTime - startTime)

# Compute final avg times

time1 = time1 / INSTANCES

time2 = time2 / INSTANCES

print("The average time for Merge Sort is: {:.8f} s".format(time1))

print("The average time for Brute Force Sort is: {:.8f} s".format(time2))