(Python) This is my code for printing a roster for a team. When I print to...

70.2K

Verified Solution

Question

Programming

(Python) This is my code for printing a roster for a team. WhenI print to the console, it makes the first player's name show up asnumber 2, and it says [] (its just blank for 1). How can I fix thatso the first player's name is 1, not skipping 1 and going to 2.

def file_to_dictionary(rosterFile):

myDictionary={}

myDict=[]

  

with open(rosterFile,'r') as f:

for line in f:

  

(num,first,last,position)=line.split()

myDictionary[num]= myDict

myDict=[first, last, position]

print (myDictionary)

return myDictionary

  

file_to_dictionary((f\"../data/playerRoster.txt\"))

  

Answer & Explanation Solved by verified expert
4.3 Ratings (765 Votes)
In this program I see that you are trying to read a file line by line and create a dicitionary out of the data in it Also i assume that the data in each line are seperated by spaces and that is why you are using linesplit With those assumptions in mind I see a    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students