Skip to main content

Posts

Showing posts from July, 2025

DATAFRAME IMP QUESTIONS

  Q30. Consider the following CORONA DataFrame and answer the questions given below: ID State Cases 100 Delhi 3000 110 Mumbai 4000 120 Chennai 5000 130 Surat 4500 Create the above dictionary and DataFrame with given data and perform the following operations: (a) Write code to add a new column named 'Recovery' using the Series method. This column should store the number of patients recovered in each state. (Assume appropriate values) (b) Add a new column named 'Deaths' using the assign() method to store the number of deaths in each state. (Assume values) (c) Add a new row using loc[] to store details of another state. (Assume values) (d) Add a new column named 'Percentage' using the insert() method. This column should store the percentage of recovery in each state and must...

GRADE XII - BINARY BASIC PROJECT - 29 JULY

  BINARY BASIC PROJECT """ Created on Mon Jul 28 11:34:41 2025 @author: Kirti Hora """ import pickle from os import remove, rename # OS is a built-in Python module that allows you to interact with the operating system # remove and rename : These functions help in deleting and renaming files . def createfile():     file = open("item.dat","wb")     ans = "y"     while ans == "y":         ino = int(input("\nitem no -"))         name = input("\nName- ")         price = float(input("\nPrice -"))         qty = int(input("\nQuantity -"))         itdets = [ino,name,price,qty]         pickle.dump(itdets,file)         ans = input("add more ?(y/n) - ")     file.close() def display_count():     totrec = 0     try:         with open("item.dat", "rb") as fin:     ...

GRADE XII - CS - Exception Handling

  Exception Handling When a program runs, sometimes errors can occur (like dividing by zero or trying to open a file that doesn't exist). These errors are called exceptions. Exception Handling allows the program to respond to errors gracefully instead of crashing. Why Use Exception Handling? Prevents the program from crashing. Helps in debugging. Makes the program user-friendly.   Example Without Exception Handling a = int(input("Enter a number: ")) b = int(input("Enter another number: ")) print("Result:", a / b)         # If b = 0, program crashes!   If the user enters 0 for b, it shows: ZeroDivisionError: division by zero   Using Try-Except to Handle Exceptions try:     a = int(input("Enter a number: "))     b = int(input("Enter another number: "))     print("Result:", a / b) except ZeroDivisionError:     print("You cannot divide ...

GRADE XII - BINARY FILES | 22 Aug

  Write & Read a List to a Binary File import pickle my_list = [10, 20, 30, 40, 50] file = open("data.dat", "wb")   # open file in write-binary mode pickle.dump(my_list, file)      # write the list to the file file.close()                    # don't forget to close the file print("List successfully written to binary file.") read-binary mode file = open("data.dat", "rb")    # open file in read-binary mode loaded_list = pickle.load(file)   # read the list from the file file.close() print("List read from binary file:", loaded_list) Notes: wb = write binary rb = read binary pickle.dump(obj, file) → writes object to file pickle.load(file) → reads object from file Write a Dictionary to a Binary File import pickle # Dictionary to write my_dict = {     "name": "Pooja",     "age": 2...