Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Use the NBA-Attendance-2015.txt and the 2-4-1ReadingFiles jupyter program as a starting point to read in the data. Each line should be a string using string

Use the NBA-Attendance-2015.txt and the 2-4-1ReadingFiles jupyter program as a starting point to read in the data.

Each line should be a string using string and number formatting that puts the team, total attendance, average attendance, and capacity into a formatted string.

Each line should look something like: 'The overall attendance at Atlanta was 13,993, average attendance was 9,456 and the capacity was 102.06%'

Make sure the Attendance has appropriate commas and capacity has a 2 decimals and a % sign.

Below is the jupyter program as the starting point.

# Program used: 2-5-1ReadingFiles.ipynb

# This program reads a file and prints the lines and creates a list of items on the line

# open the file for reading (in the same directory as the program)

NBAfile = open ('NBA-Attendance-2015.txt', 'r')

# iterate over the lines of the file and count the number of lines

count = 0

NBAlist = [ ]

for line in NBAfile:

# increment adds one to the count variable

count += 1

# strip the newline at the end of the line (and other white space from ends)

textline = line.strip() #

split the line on whitespace items = textline.split()

# add the list of items to the NBAlist

NBAlist.append(items)

# print the number of teams read

print('Number of teams: ', count)

# print the lines from the list

for line in NBAlist: print ('Line: ', line)

NBAfile.close()

This is the txt file looks like. There are a few lines which have word values as line 5, 8.

1 Bulls 894659 21820 104.3 2 Cavaliers 843042 20562 100 3 Mavericks 825901 20143 104.9 4 Raptors 812863 19825 100.1 5 NY Knicks 812292 19812 100 6 Heat 809350 19740 100.7 7 Warriors 803436 19596 100 8 Trail Blazers 794085 19367 99.6 9 Jazz 791489 19304 97 10 Clippers 786910 19192 100.7 11 Lakers 778877 18997 99.7 12 Spurs 756445 18449 99.3 13 Celtics 749076 18270 98.1 14 Thunder 746323 18203 100 15 Rockets 737244 17981 99.7 16 Wizards 725426 17693 87.3 17 Magic 719275 17543 93.1 18 Hornets 716894 17485 91.7 19 Kings 707526 17256 99.7 20 Suns 701405 17107 92.9 21 Pacers 690733 16847 92.7 22 Hawks 690150 16832 89.9 23 Pelicans 688549 16793 97.7 24 Grizzlies 684603 16697 92.2 25 Pistons 677138 16515 74.8 26 Bucks 621808 15166 81 27 Nets 620142 15125 83.6 28 76ers 610121 14881 73.2 29 Timberwolves 581178 14175 73.2 30 Nuggets 577898 14095 73.6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. Identify the call to adventure in Rocky.

Answered: 1 week ago