Comprehension

Arjun has been given following incomplete code, which takes a student details (name, marks) and writes into a binary file student.dat.
import pickle
stname = input("enter name")
stmarks int(input ("enter marks"))
stdict ("Name" : stname, "Marks" : stmarks)
           _________     :      \( \#\) line 1
          _________      :     \(\#\) line  2
           _________     :      \( \#\) line 3
           _________     :      \(\#\) line 4           
 
print (r)
if r["marks"] \(>=\) 85:
          print("eligible for scholarship") 
else:
          print("not eligible for scholarship")
Complete code for line 1 to open the given binary file in f object using with statement:

Question: 1

Complete code for line 1 to open the given binary file in f object using with statement:

Updated On: Oct 18, 2024
  • with open(student.dat, "w") as f:
  • with open("student.dat ""wb") as f:
  • with open("student.dat ",w) as f:
  • with open("student.dat","wb") in f:
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

The correct option is (B) : with open("student.dat ""wb") as f:
Was this answer helpful?
0
0
Question: 2

Identify correct code for line 2 to write the contents in the file:

Updated On: Oct 18, 2024
  • f.dump()
  • pickle.dump()
  • pickle.dump(stdict)
  • pickle.dump(stdict,f)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

The correct option is (D) : pickle.dump(stdict,f)
Was this answer helpful?
0
0
Question: 3

Use with statement and identify correct code to open the created file for reading in fl for line 3.

Updated On: Oct 18, 2024
  • with open("student.dat","rb") as f1:
  • with open("student.dat") as f1:
  • with open("student") as fl:
  • with open("student.txt") as f1 :
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

The correct option is (A) : with open("student.dat","rb") as f1:
Was this answer helpful?
0
0
Question: 4

Complete code for line 4 to read the contents into a dictionary r:

Updated On: Oct 18, 2024
  • r pickle.load(fl)
  • pickle.load(fl) = r
  • ) fl pickle.load(r)
  • pickle.load(r) = fl
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

The correct option is (A) :r pickle.load(fl)
Was this answer helpful?
0
0
Question: 5

If we give value of name as Arun and marks as 86 then the output is:

Updated On: Oct 18, 2024
  • {Name: Arun, Marks-86}
  • {{Name: Arun},{Marks:86}}eligible for scholarship
  • {Name: Arun,Marks:86}eligible for scholarship
  • eligible for scholarship
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

The correct option is (C) :{Name: Arun,Marks:86}eligible for scholarship
Was this answer helpful?
0
0

Top Questions on Reading Comprehension

View More Questions