Learning about readline and writeline method in Pytthon( Beginner). I wrote a program but couldn’t understand the output. /u/FewNectarine623 Python Education

f = open('shiv.txt', 'r') i = 0 while True: i = i + 1 line = f.readline() if not line: break print(line,end="") m1 = line.split(",")[0] m2 = line.split(",")[1] m3 = line.split(",")[2] print(f"Marks of student {i} in Maths is: {m1*2}.") print(f"Marks of student {i} in English is: {m2*2}.") print(f"Marks of student {i} in SST is: {m3*2}.") 

shiv.txt

23,34,56

34,45,67

56,78,90

Link to output

I know I need to typecast to int but I want to know why in my o/p 56 and 67 are in new lines and also two fullstops in new lines?? whereas 90 & 90 is in the same line with the fullstop? What is the logic?

submitted by /u/FewNectarine623
[link] [comments]

​r/learnpython f = open(‘shiv.txt’, ‘r’) i = 0 while True: i = i + 1 line = f.readline() if not line: break print(line,end=””) m1 = line.split(“,”)[0] m2 = line.split(“,”)[1] m3 = line.split(“,”)[2] print(f”Marks of student {i} in Maths is: {m1*2}.”) print(f”Marks of student {i} in English is: {m2*2}.”) print(f”Marks of student {i} in SST is: {m3*2}.”) shiv.txt 23,34,56 34,45,67 56,78,90 Link to output I know I need to typecast to int but I want to know why in my o/p 56 and 67 are in new lines and also two fullstops in new lines?? whereas 90 & 90 is in the same line with the fullstop? What is the logic? submitted by /u/FewNectarine623 [link] [comments] 

f = open('shiv.txt', 'r') i = 0 while True: i = i + 1 line = f.readline() if not line: break print(line,end="") m1 = line.split(",")[0] m2 = line.split(",")[1] m3 = line.split(",")[2] print(f"Marks of student {i} in Maths is: {m1*2}.") print(f"Marks of student {i} in English is: {m2*2}.") print(f"Marks of student {i} in SST is: {m3*2}.") 

shiv.txt

23,34,56

34,45,67

56,78,90

Link to output

I know I need to typecast to int but I want to know why in my o/p 56 and 67 are in new lines and also two fullstops in new lines?? whereas 90 & 90 is in the same line with the fullstop? What is the logic?

submitted by /u/FewNectarine623
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *