KnowledgeBoat Logo

Class - 12 CBSE Computer Science Important Output Questions 2025

  • Python Functions

    Predict the output of the following code:

    def express (x, n) :
        if n == 0:
            return 1
        elif n % 2 == 0:
            return express (x*x, n/2) 
        else:
            return x * express (x, n-1) 
    express (2, 5)
    

  • Python Functions

    Predict the output of the following code:

    def Changer(P, Q = 10):
        P = P / Q
        Q = P % Q
        return P
    
    A = 200
    B = 20
    A = Changer(A, B)
    print(A, B, sep = '$')
    B = Changer(B)
    print(A, B, sep = '$', end = '###')
    

  • Python File Handling

    What will be the output of the following code ?

    import pickle                             
    ID = {1:"Ziva", 2:"53050", 3:"IT", 4:"38", 5:"Dunzo"}                                    
    fin = open("Emp.pkl","wb")
    pickle.dump(ID, fin)                     
    fin.close()                      
    fout = open("Emp.pkl",'rb')
    ID = pickle.load(fout)
    print(ID[5])
    

  • Python File Handling

    What will be the output of the following code ?

    import pickle
    List1 = ['Roza', {'a': 23, 'b': True}, (1, 2, 3), [['dogs', 'cats'], None]] 
    List2 = ['Rita', {'x': 45, 'y': False}, (9, 5, 3), [['insects', 'bees'], None]] 
    with open('data.pkl', 'wb') as f:    
        f.write(List1)
    with open('data.pkl', 'wb') as f:
        f.write(List2)            
    with open('data.pkl', 'rb') as f:     
        List1 = pickle.load(f)
    print(List1)
    

  • Python File Handling

    What is the output of the following considering the file data.csv given below.

        File data.csv contains:
    Identifier;First name;Last name
    901242;Riya;Verma
    207074;Laura;Grey
    408129;Ali;Baig
    934600;Manit;Kaur
    507916;Jiva;Jain
    

    import csv
    with open('C:\data.csv', 'r+') as f: 
      data = csv.reader(f)
      for row in data: 
          if 'the' in row :
              print(row)
    

  • Python Data Handling

    What is the output of the following code fragment? Explain.

    fout = open("output.txt", 'w') 
    fout.write("Hello, world! \n") 
    fout.write("How are you?") 
    fout.close()
    f = open("output.txt")
    print(f.read())
    

  • Python Data Handling

    Write the output of the following code with justification if the contents of the file "ABC.txt" are:

    "Welcome to Python Programming!"

    f1 = open("ABC.txt", "r")
    size = len(f1.read())
    print(size)
    data = f1.read(5)
    print(data)
    

  • Python Data Handling

    Give the output of the following snippet:

    import pickle
    list1, list2 = [2, 3, 4, 5, 6, 7, 8, 9, 10], []
    for i in list1:
        if (i % 2 == 0 and i % 4 == 0):
            list2.append(i)
    f = open("bin.dat", "wb")
    pickle.dump(list2, f)
    f.close()
    f = open("bin.dat", "rb")
    data = pickle.load(f)
    f.close()
    for i in data: 
        print(i)
    

  • Linear Lists

    Predict the output of following code if the input is :

    (i) 12, 3, 4, 5, 7, 12, 8, 23, 12

    (ii) 8, 9, 2, 3, 7, 8

    Code :

    s = eval(input("Enter a list : "))
    n = len(s)
    t = s[1:n-1]
    print(s[0] == s[n-1] and
    t.count(s[0]) == 0)
    

  • Linear Lists

    Predict the output :

    def h_t(NLst):                
        from_back = NLst.pop()            
        from_front = NLst.pop(0)
        NLst.append(from_front)
        NLst.insert(0, from_back)
    NLst1 = [[21, 12], 31]
    NLst3 = NLst1.copy()
    NLst2 = NLst1
    NLst2[-1] = 5
    NLst2.insert(1, 6)
    h_t(NLst1)
    print(NLst1[0], NLst1[-1], len(NLst1)) 
    print(NLst2[0], NLst2[-1], len(NLst2)) 
    print(NLst3[0], NLst3[-1], len(NLst3))
    

Showing 61 - 70 of 98 Questions