Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have been hired by a major robotic pilot training and robot design contract

ID: 3744478 • Letter: Y

Question

You have been hired by a major robotic pilot training and robot design contract firm to process the data from their most recent field tests in multiple training sites. To make this process easier on yourself, you have decided to write a Python script to automate the process. The company wants the following data on their robots for the training sites:

1) The information of the best pilot, as quantified by their field test average

2) The average performance of each field test

3) A histogram of robot colors from a giving training site

5) The average first and last name lengths, rounded down

Many of these stats seem arbitrary, almost as if they were made for pointless reasons of testing Python skills.

Briefly look over the two .csv files provided. Both were generated using Mockaroo, a random data generation tool.

Perform the following steps:

Prompt for a file name. Read in that file name.

Set up a dictionary to act as a histogram for the robot colors

Calculate the stats specified above. Use whatever data structures you feel you may need - lists, dictionaries, etc

Print the final report to both the console using print and to a file called fn_report.txt. So, if the filename is Pilots1.csv, save the data to Pilots1_report.txt

Below is sample output for Pilots1.csv

Enter a pilot data file name: Pilots1.csv

Test Site Report:

Average first name length: 6

Average last name length: 7

Average field test 1 score: 75

Average field test 2 score: 68

Average field test 3 score: 68

Best pilot data:

Marietta Senn, serial RS:738_1344, Orange, with an average field test score of 99

Colors Histogram---

{'Aquamarine': 54,

'Blue': 66,

'Crimson': 54,

'Fuscia': 50,

'Goldenrod': 44,

'Green': 56,

'Indigo': 44,

'Khaki': 61,

'Maroon': 61,

'Mauv': 35,

'Orange': 57,

'Pink': 47,

'Puce': 54,

'Purple': 51,

'Red': 59,

'Teal': 53,

'Turquoise': 55,

'Violet': 47,

'Yellow': 52}

File Home Insert Page Layout Formulas Data Review View Help TEA Tell me wha fid first_nam last_name gender robot_ser robot_col field_test field_test field_test_3 1 Joletta Dimeloe Female RS:639_71 Indigo 2 Ketti 3 Felizio Hobden Male 4 Ferdinand RontreeFemale RS:141 65 Maroon 5 Dorelle Kleinsmur Female RS:671_36 Turquoise 6 Gwenni Helstrip Female RS:016_12 Blue 7 Laina HuwsFemale RS:858 43 Violet 8 Whitman Harriagn Male 9 Fonz 57 39 81 Fahy Female RS:438 58 Mauv 78 92 4 RS:786 03 Fuscia 78 54 83 79 97 RS:298 62 Turquoise RS:188_93 Orange RS:062 04 Violet 95 73 69 Yakubov Male 74 81 87 97 87 53 74 10 Edlin 11 Noellyn Searjeant Female RS:010_74 Red 12 Jessa McPhader Female RS:557 18 Crimson 13 Kermie Daid 14 Shelby Gueste Female RS:876 75 Green 15 Onfre Astall 16 Moria Bowley Female RS:827_50 Pink 17 Julieta Coveley Female RS:454_74 Violet 18 Axel 19 Tristam Aspel Pursglove Male 53 81 63 61 73 39 83 53 89 97 52 79 51 Male RS:974_27 Orange 16 Male RS:768 36 Blue 18 19 53 76 49 61 Togwe Male Male RS:399 44 Orange RS:502 38 Turquoise

Explanation / Answer

#Assumption :- the Format of the input csv file is exactly the same as given in the example above

# i.e ,the zeroth filed is 'id', the first field is 'First name',Second field is 'Last name' , Third # Field is 'gender',

# Fourth Field is 'robot Serial', Fifth is 'robot color' and the Last three fields are field test

# scores

import csv

# remember to ask for a file name from input and store that in 'filename'

filename = input("Enter a pilot data file name: ")

fieldNames = []

rows = []

with open(filename,'r') as csvfile:

csvreader = csv.reader(csvfile)

fieldNames = csvreader.next()

for row in csvreader:

rows.append(row)

# first find the the average first name length and last name length rounded down

avgFirst = 0

avgLast = 0

#assuming the first field contains the first name and the second field contains the Last name

rowLen = 0

for row in rows:

avgFirst += len(row[1])

avgLast += len(row[2])

rowLen += 1

avgFirst = int(avgFirst/rowLen)

avgLast = int(avgLast/rowLen)

# Get the average Field test scores , assuming that there are only 3 field test scores

avgFieldOne = 0

avgFieldTwo = 0

avgFieldThree = 0

for row in rows:

avgFieldOne += int(row[6])

avgFieldTwo += int(row[7])

avgFieldThree += int(row[8])

avgFieldOne = int(avgFieldOne/rowLen)

avgFieldTwo = int(avgFieldTwo/rowLen)

avgFieldThree = int(avgFieldThree/rowLen)

# Getting Color Histograms, color histogram is represented by a dict

colorHistogram = dict()

for row in rows:

#row[5] represents the color

if row[5] in colorHistogram:

colorHistogram[row[5]] += 1

else:

colorHistogram[row[5]] = 1

# Find the best Pilot by their Field Test Score

bestId = 0

bestFieldTestSum = 0

for row in rows:

tempFieldTestSum = int(row[6]) + int(row[7]) + int(row[8])

if(tempFieldTestSum > bestFieldTestSum):

bestFieldTestSum = tempFieldTestSum

bestId = int(row[0]) - 1

bestPilot = dict()

bestPilot["FirstName"] = rows[bestId][1]

bestPilot["LastName"] = rows[bestId][2]

bestPilot["serialRS"] = rows[bestId][4]

bestPilot["Color"] = rows[bestId][5]

bestPilot["AvgScore"] = str( int(bestFieldTestSum/3) )

#printing the data to the Console Now

#Printing average First name length and Last Name length

print("Average first name length: %d"%avgFirst)

print("Average Last name length: %d"%avgLast)

# Printing the three Field Test Scores' average

print("Average field test 1 Score: %d"%avgFieldOne)

print("Average field test 2 Score: %d"%avgFieldTwo)

print("Average field test 3 Score: %d"%avgFieldThree)

#printing the best pilot data

print(bestPilot["FirstName"] + " " + bestPilot["LastName"] + ",serial RS: " +bestPilot["serialRS"] + ","+bestPilot["Color"] + ", with an average field Test Score of " + bestPilot["AvgScore"])

#printing the colors Histogram

for color in colorHistogram:

print(color + " : " + str(colorHistogram[color]) +",")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote