Question: In Python I am using this file Criteria.txt and it looks like this Homework,5,10,10 Quiz,3,20,20 Midterm,1,50,30 Final,1,100,40 I typed in this code to open and
In Python I am using this file Criteria.txt and it looks like this
Homework,5,10,10 Quiz,3,20,20 Midterm,1,50,30 Final,1,100,40
I typed in this code to open and manipulate the Criteria.txt file
>>> criteria=open('Criteria.txt','r')
>>> criteria_line=criteria.readline()
>>> criteria_myline=criteria_line.strip().split(',')
>>> for criteria_line in criteria:
... print (criteria_line),
... criteria_myline = criteria_line.strip().split(',')
... print ("Assignment Type: "+criteria_myline[0])
... print ("Number: "+ criteria_myline [1])
... print ("Points: "+ criteria_myline [2])
... print ("Weight: "+ criteria_myline [3])
... print ()
and the result was this
Quiz,3,20,20
(None,)
Assignment Type: Quiz
Number: 3
Points: 20
Weight: 20
Midterm,1,50,30
(None,)
Assignment Type: Midterm
Number: 1
Points: 50
Weight: 30
Final,1,100,40
(None,)
Assignment Type: Final
Number: 1
Points: 100
Weight: 40
This was all correct except Homework didn't show up. You can see in the Criteria.txt file hat Homework was also in the list. What is wrong with this code? Why did it leave Homework out? What is the right code?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
