0% found this document useful (0 votes)
58 views9 pages

Xii CS Python Programs 2023 2024 - 240226 - 192836

Computer science

Uploaded by

geetha lenin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views9 pages

Xii CS Python Programs 2023 2024 - 240226 - 192836

Computer science

Uploaded by

geetha lenin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

https://sites.google.

com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM


XII STD COMPUTER SCIENCE – Python Programs 2023 - 2024
Sl.No Program Output
x=int(input("Enter your age :")) Enter your age :21
1. if if x>=18: you are eligible for voting
print("you are eligible for voting")

a=int(input("Enter any number :")) Enter any number :5


if a%2==0: 5 is an odd number
2. if..else print(a, "is an even number ")
else : Enter any number :6
print(a, "is an odd number ") 6 is an even number
m1=int(input("Enter mark in first subject Enter mark in first subject :85
:")) Enter mark in second subject :90
m2=int(input("Enter mark in second subject Grade : A
:"))
avg=(m1+m2)/2 Enter mark in first subject :45
if avg>=80: Enter mark in second subject :50
print("Grade : A") Grade:E
3. if..elif..else elifavg>=70 and avg<80:
print("Grade: B")
elifavg>=60 and avg<70:
print("Grade:C")
elifavg>=50 and avg<60:
print("Grade:D")
else :
print("Grade:E")
ch=input("Enter a Character:") Enter a Character:E
4. in if ch in ('a','A','e','E','i','I','o','O','u','U'): E is a vowel
print(ch, 'is a vowel')
ch=input("Enter a Character:") Enter a Character: b
if ch not in ('a','A','e','E','i','I','o','O','u','U'): b is consonant
5. not print(ch, 'is consonant') Enter a Character: a
else: a is vowel
print(ch, 'is vowel')
i=10 10 11 12 13 14 15
6. while while(i<=15):
print(i,end='\t')
i=i+1
i=10 10 11 12 13 14 15
while(i<=15): Exit Loop 16
7. while …else print(i,end='\t')
i=i+1
else:
print("\n Exit Loop 16")
for x in "Hello World": Hello World
8.for
print(x,end='')
for x in(1,2,3,4,5): Hello World
print("Hello World") Hello World
9.for Hello World
Hello World
Hello World
for i in range(2,10,2): 2468
10. range
print(i,end=' ')
for i in range(2,10,2): 2468
print(i,end=' ') End of the Loop
11. for ..else else:
print("\n End of the Loop")
for word in 'computer': computer
print(word,end=' ') End of the Loop
12. for ..else else:
print("\n End of the Loop")

1 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT


https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
i=1 1
while(i<=5): 1 2
for j in range (1,i+1): 1 2 3
13. Display
print(j,end='\t') 1 2 3 4
print(end='\n') 1 2 3 4 5
i+=1
i=1 1
while(i<=5): 2 2
for j in range (1,i+1): 3 3 3
14. Display print(i,end='\t') 4 4 4 4
print(end='\n') 5 5 5 5 5
i+=1

for word in "Jump Statement": Jump Stat


if word == 'e': End of the Loop
print("\n End of the Loop") End of the program
15.break break
else:
print(word,end='')
print("End of the program")
for word in "Jump Statement": Jump Statmnt
if word == 'e': End of the program
continue
16. continue
print(word,end='')
print("\n End of the program")

a=int(input("Enter anynumber:")) Enter anynumber:3


if (a==0): non zero value accepted
17. pass pass
else:
print("non zero value accepted ") Enter anynumber:0
ch=input("Enter a Character:") Enter a Character:a
if ch in ('a','A','e','E','i','I','o','O','u','U'): a is a vowel
18. vowel or not print(ch, 'is a vowel')
else: Enter a Character:b
print(ch , 'is not vowel') b is not vowel
a=int(input("Enter the a number: ")) Enter the a number: 150
b=int(input("Enter the b number: ")) Enter the b number: 250
c=int(input("Enter the c number: ")) Enter the c number: 350
if (a<b) and (a<c): 150 is smallest
19. smallest 3
print(a, 'is smallest')
numbers
elif (b<a) and (b<c):
print(b, 'is smallest')
else:
print(c, 'is smallest')
a=int(input("Enter the a number: ")) Enter the a number: 35
b=int(input("Enter the b number: ")) Enter the b number: 45
c=int(input("Enter the c number: ")) Enter the c number: 50
if (a>b) and (a>c): 50 is Largest
20. Largest 3
print(a, 'is Largest')
numbers
elif (b>a) and (b>c):
print(b, 'is Largest')
else:
print(c, 'is Largest')
a=int(input("Enter the a number: ")) Enter the a number: 15
if a>0: 15 is positive
21.Given number print(a, 'is positive') Enter the a number: -10
Positive or negative elif a<0: -10 is negative
or zero print(a,'is negative') Enter the a number: 0
else: 0 is zero
print(a, 'is zero')

2 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT


https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
yr=int(input("Enter the a number: ")) Enter the a number: 2024
if yr%400==0 or yr%4==0 or yr%100==0: The year is a leap year
22. Given Year -
print('The year is a leap year')
Leap year or not
else: Enter the a number: 2023
print('The year is not a leap year') The year is not a leap year
a=0
b=1
n=int(input("Enter a number of terms: "))
print(a,end=' ')
23. N- Fibonacci print(b,end =' ') Enter a number of terms: 8
series for i in range(3,n+1): 0 1 1 2 3 5 8 13
c=a+b
print(c,end=' ')
a=b
b=c
s=0 Enter a number of terms: 10
n=int(input("Enter a number of terms: ")) sum= 55
24. Sum of natural
for i in range(1,n+1):
numbers
s=s+i
print("sum=",s)
n=int(input("Enter a number : ")) Enter a number : 1221
temp=n given number is palindrome
rev=0
while n>0:
dig=n%10 Enter a number : 175
25. Given number
rev=rev*10+dig Given number is not palindrome
Palindrome or not
n=n//10
if(temp==rev):
print("given number is palindrome")
else:
print("Given number is not palindrome")
str="*" *****
i=5 ****
26. Display format while i>=0: ***
print(str*i) **
i-=1 *
str="*" *
i=1 **
27. Display format while i<=5: ***
print(str*i) ****
i+=1 *****
for i in range (1,6,1): A
ch=65 AB
28. Display format for j in range(ch,ch+i,1): ABC
print(chr(j),end=' ') ABCD
print() ABCDE
for i in range (1,6,1): E
ch=69 ED
29. Display format for j in range(ch,ch-i,-1): EDC
print(chr(j),end=' ') EDCB
print() EDCBA

str="COMPUTER" COMPUTER
COMPUTE
index=len(str) COMPUT
30. Display format for i in str: COMPU
COMP
print(str[0:index]) COM
index-=1 CO
C

3 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT


https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
str1="COMPUTER" C
CO
index=0 COM
31. Display format for i in str1: COMP
COMPU
print(str1[:index+1]) COMPUT
index+=1 COMPUTE
COMPUTER
101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135
for i in range (101,1000,2): 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171
173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207

print(i, end=' ') 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243
245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279
281 283 285 287 289 291 293 295 297 299 301 303 305 307 309 311 313 315
317 319 321 323 325 327 329 331 333 335 337 339 341 343 345 347 349 351
353 355 357 359 361 363 365 367 369 371 373 375 377 379 381 383 385 387
389 391 393 395 397 399 401 403 405 407 409 411 413 415 417 419 421 423
425 427 429 431 433 435 437 439 441 443 445 447 449 451 453 455 457 459
461 463 465 467 469 471 473 475 477 479 481 483 485 487 489 491 493 495
32. display 3 digit 497 499 501 503 505 507 509 511 513 515 517 519 521 523 525 527 529 531
533 535 537 539 541 543 545 547 549 551 553 555 557 559 561 563 565 567
odd numbers 569 571 573 575 577 579 581 583 585 587 589 591 593 595 597 599 601 603
605 607 609 611 613 615 617 619 621 623 625 627 629 631 633 635 637 639
641 643 645 647 649 651 653 655 657 659 661 663 665 667 669 671 673 675
677 679 681 683 685 687 689 691 693 695 697 699 701 703 705 707 709 711
713 715 717 719 721 723 725 727 729 731 733 735 737 739 741 743 745 747
749 751 753 755 757 759 761 763 765 767 769 771 773 775 777 779 781 783
785 787 789 791 793 795 797 799 801 803 805 807 809 811 813 815 817 819
821 823 825 827 829 831 833 835 837 839 841 843 845 847 849 851 853 855
857 859 861 863 865 867 869 871 873 875 877 879 881 883 885 887 889 891
893 895 897 899 901 903 905 907 909 911 913 915 917 919 921 923 925 927
929 931 933 935 937 939 941 943 945 947 949 951 953 955 957 959 961 963
965 967 969 971 973 975 977 979 981 983 985 987 989 991 993 995 997 999
Enter the number:5
n=int(input("Enter the number:")) 5X1=5
5 X 2 = 10
33. n-Multiplication for i in range(1,11): 5 X 3 = 15
5 X 4 = 20
Table print(n,'x',i,"=",n*i) 5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
5 X 10 = 50
i=4
while(i<=8): 1 2 3 4
34.Ddisplay format for j in range (1,i+1): 1 2 3 4 5
print(j,end=' ') 1 2 3 4 5 6
1 2 3 4 5 6 7
print(end='\n') 1 2 3 4 5 6 7 8
i+=1
defcompute_lcm(x, y):
if x > y: Enter the number1 :54
greater = x Enter the number2 :24
else: The L.C.M. is 216
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
35.find LCM 2 numbers lcm = greater
break
greater += 1
return lcm
num1 = int(input("Enter the number1 :"))
num2 = int(input("Enter the number2 :"))
print("The L.C.M. is", compute_lcm(num1,
num2))
def factorial(x):
if x == 1: Enter the n number: 5
return 1 The factorial of 5 is 120
36. Recursive function
else:
N factorial
return (x * factorial(x-1))
num = int(input("Enter the n number: "))
print("The factorial of", num, "is", factorial(num))
str1="Welcome" WelcomeWelcomeWelcomeWelcome
37. Repeating(*)
print(str1*4)
str1="Welcome to Python" Welcome to Python
print(str1) Python
print(str1[11:17]) Pto
38. string
eg Wotyn
print(str1[11:17:2])
Mar-2020 nytoW
print(str1[::4])
print(str1[::-4])

4 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT


https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM

str1="THIRUKKURAL"
print(str1)
print(str1[0]) THIRUKKURAL
print(str1[0:5]) T
THIRU
print(str1[:5]) THIRU
39. string eg print(str1[6:]) KURAL
print(str1[6:10:2]) KR
print(str1[::4]) TUR
print(str1[::-4]) LKI
print(str1[-4]) U
print(str1[-4:]) URAL

str1="How are you" How are you


40. character replace print(str1) Hew are yeu
print(str1.replace("o","e"))
def reverse(str1):
str2='' Enter a String:malayalam
for i in str1: Given String is palindrome
str2=i+str2 The reverse of the given string is : Malayalam
if str1==str2: Enter a String:welcome
41.Given String is print("Given String is palindrome") Given String is not palindrome
Palindrome or not else: The reverse of the given string is : emoclew
print("Given String is not palindrome")
return str2
word=input("\n Enter a String:")
print("The reverse of the given string is
:",reverse(word))
str1=input("Enter the String :")
str2="aAeEiIoOuU"
v,c=0,0
for i in str1: Enter the String :Tamilnadu School Education
42. number of vowels The given string contains 11 vowels and 13
if i in str2: consonants
and consonants in
v+=1
Given String
elifi.isalpha():
c+=1
print("The given string contains {} vowels and {}
consonants".format(v,c))
str1="ABCDEFGH" Aate Bate Cate Date Eate
str2="ate"
43. output
for i in str1: Fate Gate Hate
print((i+str2),end='\t')
ount(s,c): Enter the String :Software
c1=0
for i in s: Engineering
if i == c: Enter the character search:e
c1+=1
44. count the occurs a
return c1
The given character e is occurs
character in string 3 times in the given string
str1=input("Enter the String :")
ch=input("Enter the character search:")
cnt=count(str1,ch)
print("The given character {} is occurs {} times in
the given string ".format(ch,cnt))
str1="welcome" Weol
str2="to school"
45.output
str3=str1[:2]+str2[len(str2)-2:]
print(str3)
str1="nathan" Nathan
46. capitalize() and str2="sAmI.NaThAn"
Swapcase() eg print(str1.capitalize())
SaMi.nAtHaN
print(str2.swapcase())
str1="welcome" Well
str2="to school"
47 .output
str3=str1[:3]+str2[len(str2)-1:]
print(str3)

5 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT


https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
str1="THOLKAPPIYAM" KAPPIYAM
print(str1[4:]) KPIA
48. Output print(str1[4::2]) TLPY
print(str1[::3]) MIAO
print(str1[::-3])
str="COMPUTER SCIENCE" COMPUTER SCIENCECOMPUTER SCIENCE
COMPUTE
49. Output print(str*2)
print(str[0:7])
str1="mukhasaparur"
str2="CUDDALORE"
print(str1.upper())
print(str1.isupper()) MUKHASAPARUR
50.Output
print(str2.isupper()) False
True
print(str2.lower())
cuddalore
print(str2.islower()) False
print(str1.islower()) True
str1="welcome"
51.Output print(str1.center(15,'*')) ****welcome****
print(len(str1))
7
marks=[10,20,30,40,50]
print(marks[0]) 10
52.List eg 50
print(marks[-1]) 30
print(marks[2])
marks=[10,20,30,40,50] 10
i=0 20
30
53. list elements while i<=4: 40
print(marks[i]) 50
i=i+1
marks=[10,20,30,40,50] 50
i=-1 40
30
54.List (Reverse Index) while i>=-5: 20
print(marks[i]) 10
i=i-1
marks=[10,20,30,40,50] 10
for i in marks: 20
55. list using for 30
print(i) 40
50
marks=[10,20,30,40,50]
marks.append(60)
print(marks) [10, 20, 30, 40, 50, 60]
56. Adding elements in
a list eg
marks.extend([70,80,90])
print(marks) [10, 20, 30, 40, 50, 60, 70, 80, 90]
marks.insert(2,25)
print(marks) [10, 20, 25, 30, 40, 50, 60, 70, 80, 90]
marks=[10,20,30,40,50]
del marks[1]
print(marks) [10, 30, 40, 50]
57. Deleting elements
from list
marks.remove(40)
print(marks) [10, 30, 50]
marks.clear()
print(marks) []
58. list and range( ) for x in range(1,11): 1 2 3 4 5 6 7 8 9 10
function print(x,end=' ')
59. list and range( ) for x in range(2,11,2): 2 4 6 8 10
function print(x,end=' ')
6 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT
https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
squares=[]
for x in range(1,11):
60. Output s=x**2
squares.append(s) [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
print(squares)
squares=[x**2 for x in range(1,11)] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
61.Output
print(squares)
marks=[10,20,4,40,40,5]
x=marks.copy()
print(x) [10, 20, 4, 40, 40, 5]
x=marks.count(40)
print(x) 2
x=marks.index(20)
print(x) 1
62.Output
marks.reverse()
print(marks) [5, 40, 40, 4, 20, 10]
marks.sort()
print(marks) [4, 5, 10, 20, 40, 40]
print(max(marks)) 40
print(min(marks)) 4
print(sum(marks)) 119
list1=[2,4,6,[1,3,5]]
63. Output x=len(list1)
print(x) 4
list=[2**x for x in range(5)]
64.Output
print(list) [1, 2, 4, 8, 16]

A={x*3 for x in range(1,6)} {3, 6, 9, 12, 15}


B={y**2 for y in range(1,10,2)}
print(A) {1, 9, 81, 49, 25}
print(B)
print(A|B) {1, 3, 6, 9, 12, 15, 81, 49, 25}
65. Output
print(A-B)
print(A&B) {3, 12, 6, 15}
print(A^B)
{9}

{1, 3, 6, 12, 15, 81, 25, 49}

N=[]
for x in range(1,11): (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
N.append(x) [2, 4, 6, 8, 10]
Num=tuple(N)
print(Num)
66. Output
for index, i in enumerate(N):
if(i%2==1):
del N[index]
print(N)

Mytuple=tuple([x**2 for x in range(2,11,2)]) (36,)


print(Mytuple[2:3])
67. Output print(Mytuple[3:1]) ()
print(Mytuple[:])
(4, 16, 36, 64, 100)

7 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT


https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM

class sample: value of x= 10


x,y=10,20 value of y= 20
s=sample() value of x and y= 30
68. Output
print("value of x=",s.x)
print("value of y=",s.y)
print("value of x and y=",s.x+s.y)
class student:
mark1,mark2,mark3=45,91,71 Total Marks= 207
def process(self):
sum=student.mark1+student.mark2+student.mark3
Average Marks= 69.0
avg=sum/3
69.Output print("Total Marks=",sum)
print("Average Marks=",avg)
return
s=student()
s.process()
class odd_even: Enter a value:6
even=0
def check(self,num): 6 is Even number
if num%2==0:
print(num,"is Even number")
70.Output
else: Enter a value:5
print(num,"is Odd number")
n=odd_even() 5 is Odd number
x=int(input("Enter a value:"))
n.check(x)
class sample:
def __init__(self,num): Constructor of class sample...
print("Constructor of class sample...") The value is : 10
71.Output
self.num=num
print("The value is :",num)
s=sample(10)
class sample:
num=0 The object value is= 15
def __init__(self,var): The count of object created= 1
sample.num+=1 The object value is= 35
self.var=var The count of object created= 2
72.Output (init) print("The object value is=",self.var)
The object value is= 45
print("The count of object
created=",sample.num) The count of object created= 3
s1=sample(15)
s2=sample(35)
s3=sample(45)

class sample:
num=0 The object value is= 15
def __init__(self,var): The value of class variable is= 1
sample.num+=1 The object value is= 35
self.var=var
The value of class variable is= 2
print("The object value is=",self.var)
print("The value of class variable The object value is= 45
73.Output (del) is=",sample.num) The value of class variable is= 3
def __del__(self): Object with value 15 is exit from the scope
Object with value 35 is exit from the scope
sample.num-=1
Object with value 45 is exit from the scope
print("Object with value %d is exit from
the scope"%self.var)
s1=sample(15)
s2=sample(35)
s3=sample(45)
del s1,s2,s3

8 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT


https://sites.google.com/view/tn-computer-science/home or Google Search : TN CS ONLINE EXAM
class circle:
pi=3.14 Enter Radius:5
def __init__(self,radius): The Area= 78.5
self.radius=radius The Circumference= 31.400000000000002
def area(self):
return circle.pi*(self.radius**2)
def circumference(self):
74.Output
return 2* circle.pi*self.radius
r=int(input("Enter Radius:"))
c=circle(r)
print("The Area=",c.area())
print("The
Circumference=",c.circumference())

class sample:
__num=10 10
def disp(self): 10
75.Output print(self.__num) None
s=sample()
s.disp()
print(s.disp())

class Greeting: Good Morning Bindumadhavan


def __init__(self,name):
self.__name=name
76.Output
def display(self):
print("Good Morning ",self.__name)
obj=Greeting('Bindumadhavan')
obj.display()
class Hosting: Welcome to Python Programming
def __init__(self,name):
self.__name=name
77.Output (mar-2020) def display(self):
print("Welcome to",self.__name)
obj=Hosting("Python Programming")
obj.display()
str1=input("Enter a String:") Enter a String:Chennai GHSS , saidapet
str2="Chennai" Found
78.Membership if str2 in str1:
operator (in eg) print("Found") Enter a String:cuddalore district
else: Not Found
print("Not Found")

Prepared by S. Saminathan M.C.A.,B.Ed.,M.Phil.,


Computer Instructor Grade I
GHSS – MUKHASAPARUR
[email protected]

9 S. SAMINATHAN,M.C.A.,B.Ed.,M.Phil., GHSS-MUKHASAPARUR , CUDDALORE DT

You might also like