J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
TOP IMPORTANT PROGRAM QUESTION
XII – COMPUTER SCIENCE
1. Write a Python program to display the given pattern.
COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
Output:
str="COMPUTER"
index=len(str)
for i in str:
print(str[:index])
index -= 1
2.Write a program to display
A
AB
ABC
ABCD
ABCDE
Output:
for i in range (65, 70):
for j in range (65, i+1):
print (chr(j), end= ' ')
print (end = '\n')
i+=1
3. Write the output for the following program.
i=1
while(i<=6):
for j in range(1, i):
print(j, end=‘\t’)
print(end=‘\n’)
i+=1
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
https://csknowledgeopener.com 1 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
4. Write a program to print the following pattern
*****
****
***
**
*
Output:
for i in range (5, 0, -1):
for j in range (1, i+1):
print (‘*’, end = ‘ ‘)
i+=1
print(‘\n’)
5. Program to display the following pattern
str1=' * '
i=1
while i<=5:
print (str1*i)
i+=1
Output:
*
**
***
****
*****
6.What will be output of the following Python code ?
Squares=[x **2 for x in range(1,11)]
print (Squares)
Output:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
7. What will be output of the following Python code ?
for i in range(2,10,2):
print (i,end=' ')
else:
print ("\nEnd of the loop")
Output:
2468
End of the loop
8. Write a Python code to check whether a given year is leap year or not.
CODE:
n=int(input("Enter the year"))
if(n%4==0):
print ("Leap Year")
else:
print ("Not a Leap Year")
https://csknowledgeopener.com 2 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
Output:
Enter the year 2012
Leap Year
9. What is the output of the following snippet ?
for i in range(2,10,2):
print(i, end= ‘ ’)
Output:
2468
10. What will be the output of the following code ?
list=[3 * * x for x in range(5)]
print(list)
Output:
[1, 3, 9, 27, 81]
11. What will be the output of the given Python program ?
str=“COMPUTER SCIENCE”
(a) print(str*2) (b) print(str[0 : 7])
Output:
(a) COMPUTER SCIENCECOMPUTER SCIENCE
(b) COMPUTE
12. What will be the output of the given python program?
CODE:
str1 = "welcome"
str2 = "to school"
str3=str1[:2]+str2[len(str2)-2:]
print(str3)
OUTPUT:
weol
13.Write the output for the following Python commands :
str1=''Welcome to Python''
(i) print(str1)
(ii) print(str1[11 : 17])
(iii) print(str1[11 : 17 : 2])
(iv) print(str1[: : 4])
(v) print(str1[: : −4])
Output:
i) Welcome to Python
ii) Python
iii)Pto
iv) Wotyn
v) nytoW
https://csknowledgeopener.com 3 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
14. Write the output of the following program.
class Hosting:
def__init__(self,name):
self.__name=name
def display(self):
print(“Welcome to”,self.__name)
obj=Hosting(“Python Programming”)
obj.display( )
Output:
Welcome to Python Programming
15. (i) Write a program to display all 3 digit even numbers.
lower=int(input("Enter the lower limit for the range:"))
upper=int(input("Enter the upper limit for the range:"))
for i in range(lower,upper+1):
if(i%2==0):
print(i,end=" ")
Output:
Enter the lower limit for the range:100
Enter the upper limit for the range:150
100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146
148 150
16. Write a program to display all 3 digit odd numbers.
lower=int(input("Enter the lower limit for the range:"))
upper=int(input("Enter the upper limit for the range:"))
for i in range(lower,upper+1):
if(i%2!=0):
print(i,end=" ")
Output:
Enter the lower limit for the range:100
Enter the upper limit for the range:150
100 103 105 107 109 111 113 115 117 119 121 123 125 127 129 130 131 133 139 138 141 143 145 147
149
PREPARED BY
J. ILAKKIA M.Sc., B.Ed., M.Phil.
Computer Instructor Grade-I
Govt. Hr. Sec. School
V.Pagandai, Villupuram 605 501.
https://csknowledgeopener.com 4 http://www.youtube.com/c/csknowledgeopener