Posted on Leave a comment

Notes for Class12 Computer Science Students

Coding by Kasthuri Muthu

Class 12 Computer Science – Discussion Notes

Q1. File Handling
Content of file:
This is a test.
Isn't it? I think so.

Code:
file = open("samp.txt","r")
s = file.readline().split()
print(s[0][-1])

👉 file.readline() reads first line = "This is a test.\n"
 👉 .split() → ["This", "is", "a", "test."]
 👉 s[0] = "This"
 👉 s[0][-1] = "s"
✅ Answer: s

Q2. Dictionary with ASCII
d = {ch: ord(ch) for ch in "AEIOU"}
print(d)

✅ Answer: {'A':65, 'E':69, 'I':73, 'O':79, 'U':85}

Q3. Relative Path
File path:
D:\Program\Project\Railway\Reservation.py

If current directory = Project → relative path:
 ✅ Answer: Railway/Reservation.py

Q4. Expression
7/5 + 10**2 - (25+12*2)/4

Step:
7/5 = 1.4


10**2 = 100


12*2 = 24 → 25+24 = 49 → 49/4 = 12.25


1.4 + 100 - 12.25 = 89.15


✅ Answer: 89.15

Q5. Loop Output
str1 = "hello"
c = 0
for x in str1:
    if x != 'l':
        c += 1
    else:
        continue
print(c)

👉 "hello" has 5 characters.
 👉 2 are 'l', so counted = 3.
✅ Answer: 3

Q6. File Binary Mode
f = open("DATA.TXT", "rb")


Q7. Function Prod
def Prod(v):
    print(v*v)

print(Prod(2))

Step:
Inside function: 2*2=4 → prints 4


Function returns None → so print(Prod(2)) also prints None


✅ Answer:
4
None


Q8. Function CALLME
def CALLME(M,n1=1,n2=2):
    n1=n1*n2  
    M.append(n1)
    n2+=2 → n2 =4
    M.insert(n1,n2)
    print(M,n1,n2)

D=[10,20,30,45,60,75,90,120]
CALLME(D);
CALLME(D,3)

Step:
n1=3*2=6


Append 6 → [10,20,30,45,60,75,90,120,6]


n2=4


Insert 4 at index 1 → [10,4,20,30,45,60,75,90,120,6]


✅ Answer:
[10,20,4,30,45,60,75,90,120,2] 2 4
[10,4,20,30,45,60,75,90,120,6] 6 4


Q9. Identifiers
Valid: Emp_code, bonus, Emp1, Bond007
 Invalid: While (keyword), for (keyword), #count (illegal), 123Go (digit start)

Q10. Jumble Function
msg = "Butterfly"

Final output (after processing each char) =
 ✅ Answer:
Original: Butterfly
Final: CUuTfRgLz


Q11. Error
👉 No line in this program gives error.
 ✅ Answer: No error.

Q12–14. File Programs
👉 They ask to read, copy, and process text files (like NEWS.TXT).
Use with open("file.txt") as f:


Use readlines(), split(), isupper(), write().
 (We can write model answers if needed.)



Q15. Function with list
def ZeroEnding(SCORES):
    add = 0
    for x in SCORES:
        if str(x)[-1]=='0':
            add+=x
    print(add)

👉 For [200,456,300,100,234,678] → 200+300+100=600
✅ Answer: 600

Q16(i). Global/Local
value = 50
def display(N):
    global value
    value = 25
    if N%2==0:
        value = value + N
    else:
        value = value - N
    print(value, end="#")

display(20)
print(value)

Step:
global value=25


20%2==0 → True → value=25+20=45


Prints 45#


After function call → global value=45


✅ Answer: 45#45

Q16(ii). Random Output
👉 Since randint(0,1) + randint(1,2)+1, final selections depend on random.
 ✅ Possible outputs given:
[G,'Green'], [G,'Green'], [Y,'Yellow']


[G,'Green'], [B,'Blue'], [G,'Green']


[V,'Violet'], [B,'Blue'], [B,'Blue']


[I,'Indigo'], [B,'Blue'], [B,'Blue']



Q17. Binary File Functions
(i) Enter record:
import pickle
def writeItem():
    f=open("Itemdetails.dat","ab")
    Itemno=int(input("Enter Item No: "))
    ItemName=input("Enter Item Name: ")
    Quantity=int(input("Enter Quantity: "))
    Price=int(input("Enter Price per Item: "))
    rec=[Itemno,ItemName,Quantity,Price]
    pickle.dump(rec,f)
    f.close()

(ii) Display details for quantity=10:
def readItem():
    f=open("Itemdetails.dat","rb")
    try:
        while True:
            rec=pickle.load(f)
            if rec[2]==10:
                print("Item Name:",rec[1])
                print("Quantity:",rec[2])
                print("Total Price:",rec[2]*rec[3])
    except EOFError:
        f.close()


Q18. CSV File
CSV file data:
1,Peter,3500
2,Scott,4000
5,Sam,4200

Python function to read & display:
import csv
def readcsv():
    f=open("emp.csv","r")
    data=csv.reader(f)
    for row in data:
        print(row)
    f.close()

with open("file1.txt", "r") as file1:
    words_file1 = file1.read().split()

# Read file2.txt
with open("file2.txt", "r") as file2:
    words_file2 = file2.read().split()

# Find common words
common_words = []
for word in words_file1:
    if word in words_file2 and word not in common_words:
        common_words.append(word)

# Write common words to Combinedfile.txt
with open("Combinedfile.txt", "w") as combined_file:
    for word in common_words:
        combined_file.write(word + "\n")

print("Common words have been written to Combinedfile.txt")

Posted on Leave a comment

Prerequisites for Python Training

by Kasthuri Muthu MTech

  1. Laptop / Desktop
    Windows / Linux / Mac OS.
    At least 4 GB RAM.
  2. Python Installed
    Install Python 3.10 or above from python.org.
    Ensure IDLE is working (type python in terminal/command prompt to check).
  3. Internet Connection
    Stable connection for online classes (Zoom/Google Meet).
  4. Mindset

Be curious and open to learning.
Practice after every class (minimum 30 minutes).

Posted on Leave a comment

Python fundamentals and data handling test

Related image
  1. How are string,integer and float data are represented in python?Give examples to support your answer.
  2. Which argument of print() would you set for changing the default separator and printing the following line in current line.
  3. What is dynamic typing in python? Give an example to dynamic typing?
  4. What is undefined variable in python ? Give an example?
  5. What are opeartors? What is their function? Give example of some unary and binary operators?
  6. Write a program to compute simple interest and compound interest?
  7. Differentiate between (333/222)**2 and (333.0/222)**2?
  8. write an expression that uses 3 arithmetic operators with integer literals and produces result as 99?
  9. Write a program to take a 3 digit number and then print the reversed number?i.e. if input is 876 it should print 678
  10. Write a program to take two inputs for day, month and calculate which day of the year, the given date is. For simplicity take 30 days for all months.for example if you give input as Day3, Month2 then it should print “Day of the year :33”

ALL THE BEST !!!!

Posted on Leave a comment

PYTHON FOR CLASS 11 CBSE

Python fundamentals worksheet

This exercise is to understand the basic concepts of python.

1.For the below questions write what is the result and give a reason why that is the result.
1.a) abc=123
1.b) abc*2
1.c) print(abc)
1.d) none
1.e) break = abc
1.f) print(Break)
1.g)print(“The value of break is”,break)
1.h) Name = ‘Saitech Informatics’
1.i) Name
1.j) print(name)
1.k)Name *2

2. In the below program, identify the components asked

# Python program to find the multiplication table (from 1 to 10)
num = 12
# To take input from the user
# num = int(input(“Display multiplication table of? “))
# use for loop to iterate 10 times
for i in range(1, 11):
   print(num,’x’,i,’=’,num*i)

2.a) Number of expressions in the above code and what are the list of expressions
2.b) What are the statements in the above code
2.c) Number of functions in the above code

3. Following code intends to obtain a number in variable x and then print its 5 multiples. example :x,2x,3x,4x and 5x. Fill the below code and write the output.

x=________(input(‘___________’))
firstmultiple = ________
secondmultiple = _______
thirdmultiple = x * 3
fourthmultiple=_________
fifthmultiple=___________

print(‘x=’,________)
print(_________________________________________)

4.Create data of following types using value 22. Give 2 examples foreach type of data.
4.a) Floating Point
4.b) Integer
4.c) Complex number

5. Write a program to get input of 10 numbers and print them in a reverse order.
Hint : You can use List, Integer or any functions or methods.