0% found this document useful (0 votes)
1 views3 pages

Class12 ComputerScience Test

Uploaded by

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

Class12 ComputerScience Test

Uploaded by

Disha Kharbanda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Class 12 Computer Science Test

Topics: for loops, while loops, nested loops, conditional statements with loops

Time: 90 Minutes

Maximum Marks: 50

Instructions:
1. Attempt all questions.
2. Write neat and complete answers.
3. Assume suitable input wherever required.
4. Output-based questions must include proper tracing.

Q1. What is the difference between a for loop and a while loop in Python? Give one example
of each.
[2 Marks]

Q2. Write the output of the following program:

for i in range(1, 6):


if i % 2 == 0:
print(i * 2)
else:
print(i + 1)
[3 Marks]

Q3. Write the output of the following nested loop:

for i in range(1, 4):


for j in range(i):
print(i, end=' ')
print()
[3 Marks]

Q4. Write a Python program to print all multiples of 5 between 1 and 100 using a while
loop.
[3 Marks]

Q5. Write the output of the following program:

x=1
while x <= 4:
print(x * '*')
x += 1
[3 Marks]

Q6. Write a Python program to calculate the factorial of a number using a for loop.
[4 Marks]

Q7. Write the output of the following program:

s=0
for i in range(1, 6):
if i % 2 == 0:
s += i
else:
s -= i
print(s)
[3 Marks]

Q8. Write a Python program to check whether a number is prime or not using a for loop and
conditional statements.
[4 Marks]

Q9. Write the output of the following program:

for i in range(3):
for j in range(2, 5):
if j % 2 == 0:
print(i + j, end=' ')
print()
[4 Marks]

Q10. Write a Python program using nested while loops to print the following pattern:

1
12
123
1234
[4 Marks]

Q11. Write the output of the following program:

for i in range(1, 5):


for j in range(1, i + 1):
print(j, end='')
print()
[3 Marks]
Q12. Write a Python program to count the number of digits in a number using a while loop.
[3 Marks]

Q13. Write the output of the following program:

x=5
while x > 0:
if x % 2 == 1:
print(x, end=' ')
x -= 1
[3 Marks]

Q14. Write a Python program to display the Fibonacci series up to n terms using a loop.
[4 Marks]

Q15. Write the output of the following hard nested loop program:

for i in range(1, 4):


for j in range(1, 4):
if i == j:
print('*', end=' ')
else:
print(i + j, end=' ')
print()
[4 Marks]

You might also like