Here is class 12 computer science Unit 5 [Type B] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 5 and for all chapters here.Watch all tutorials for chapter 5.
(a) this will read the entire content of the file poem.txt. (b) this will read at most 100 bytes from the file even if it has more content.
(a) my_file = open('poemBTH.txt', 'r') my_file.read() #output: God made the Earth; Man mas=de confining countries And their fancy-frozen boundaries. But with unfound boundless love I behold borderLand of my India Expanding into the world. Hail, mother of religions, lotus, scenic beauty, and sages! (b) my_file = open('poemBTH.txt', 'r') my_file.read(100) #output: God made the Earth; Man mas=de confining countries And their fancy-frozen boundaries. But with unfound
This code will generate error because of undefined s2. NameError: name 's2' is not defined
(a) A. Output1 God made the Earth; Man made confining countries And their fancy-frozen boundaries. But with unfound boundless love I behold borderLand of my India Expanding into the world. Hail, mother of religions, lotus, scenic beauty, and sages! (b) B. Output 2 God made the Earth; (c) C. Output 3 God made (d) D. Output 4 God made (e) E. Output of Readlines function is ['God made the Earth;\n', 'Man made confining countries\n', 'And their fancy-frozen boundaries.\n', 'But with unfound boundless love\n', 'I behold borderLand of my India\n', 'Expanding into the world.\n', 'Hail, mother of religions, lotus, scenic beauty, and sages!']
This code will open a file object named file and open contacts.csv in append mode for writing. In 2nd and 3rd line two input will be taken. In 4th line the both input will be appended in the open file object.
file = open("contact.csv", "r") for i in file: print("Name:",i.split(',')[0] , "\t", "Phone",i.split(',')[1]) file.close()
name = input("Enter name :") file = open("contact.csv", "r") for line in file: if name in line: print(line)
Solution:
This code is just implementing a searching program i.e. if the entered name is in the document than the whole found line is displayed.
f = open("poemBTH.txt", "r") nl = 0 for line in f: nl +=1 print(nl)
Output: 7 The above code fragment if counting the total numbers of line in the poemBTH.txt file.
Output: 1 as the filep1.txt just contain one line.
file = open("diary.txt", "r") for line in file: print(line) file.close()
file = open("mylife.txt", "w") file.write("This is the first line\n") file.write("This is the second line\n") file.write("This is the third line") file.close()
Clear Doubts with Computer TutorIn case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in
You cannot copy content of this page