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

Programs

The document contains Python programs for printing numbers, calculating sums, and various multiple-choice questions (MCQs) related to loops, Python basics, conditional statements, functions, lists, and file handling. It also includes a section on variables, explaining their definition, rules for naming, types, and advantages. Overall, it serves as a comprehensive guide for understanding basic Python programming concepts.

Uploaded by

danial92357
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 views7 pages

Programs

The document contains Python programs for printing numbers, calculating sums, and various multiple-choice questions (MCQs) related to loops, Python basics, conditional statements, functions, lists, and file handling. It also includes a section on variables, explaining their definition, rules for naming, types, and advantages. Overall, it serves as a comprehensive guide for understanding basic Python programming concepts.

Uploaded by

danial92357
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

Programs

1. Program to Print Numbers from 1 to 100


num = 1

while num <= 100:

print(num)

num += 1

2. Program to Print Even Numbers Between 1 and 100


num = 1

while num <= 100:

if num % 2 == 0:

print(num)

num += 1

3. Program to Print Odd Numbers Between 1 and 100


num = 1

while num <= 100:

if num % 2! = 0:

print(num)

num += 1

4. Write a program to find the sum of the first 50 natural numbers.


sum = 0

num = 1

while num <= 50:

sum = sum + num


num += 1

print ("Sum of first 50 natural numbers is:", sum)

11th Class Computer Science Python MCQs


Loops MCQs

1. Which loop is used when the number of iterations is known?


A) while
B) do-while
C) for
D) if

Answer: C) for

2. Which keyword is used to stop a loop?


A) skip
B) stop
C) break
D) exit

Answer: C) break

3. Which operator is used to find remainder?


A) /
B) %
C) //
D) *

Answer: B) %

4. What is the output of 5 % 2 ?


A) 2
B) 1
C) 0
D) 5

Answer: B) 1

5. Which loop checks condition first?


A) while
B) for
C) both
D) none

Answer: C) both

Python Basics MCQs

6. Python is a:
A) Low level language
B) High level language
C) Machine language
D) Assembly language

Answer: B) High level language

7. Which symbol is used for comments in Python?


A) //
B) /* */
C) #
D) --

Answer: C) #

8. Which function is used for input in Python?


A) print()
B) scan()
C) cin()
D) input ()

Answer: D) input ()

9. Which function displays output?


A) display()
B) show()
C) print()
D) output ()

Answer: C) print ()

10. Python file extension is:


A) .java
B) .cpp
C) .py
D) .html
Answer: C) .py

Conditional Statements MCQs

11. Which statement is used for decision making?


A) loop
B) if
C) print
D) input

Answer: B) if

12. Which keyword is used for another condition?


A) else if
B) elseif
C) elif
D) otherwise

Answer: C) elif

13. Which comparison operator means “not equal”?


A) =
B) ==
C) !=
D) <>

Answer: C) !=

Functions MCQs

14. Which keyword is used to define a function?


A) define
B) function
C) def
D) fun

Answer: C) def

15. A function can return value using:


A) stop
B) break
C) return
D) end
Answer: C) return

Lists MCQs

16. Which brackets are used for list?


A) ()
B) []
C) {}
D) <>

Answer: B) []

17. List items are separated by:


A) ;
B) :
C) ,
D) .

Answer: C) ,

18. Which method adds item to list?


A) insert()
B) add()
C) append()
D) push ()

Answer: C) append ()

File Handling MCQs

19. Which mode is used to read a file?


A) w
B) a
C) r
D) x

Answer: C) r

20. Which mode is used to write into file?


A) r
B) w
C) a
D) rw
Answer: B) w

Long questions
Variable
A variable is a name used to store data or value in a program.
It acts like a container that holds information that can be changed during program
execution.
In Python, variables are created when a value is assigned to them using the
assignment operator =.

Rules for Naming Variables


1. Variable name can contain letters, numbers, and underscores.
2. A variable name cannot start with a number.
3. Spaces are not allowed.
4. Python keywords cannot be used as variable names.

Example Program
name = "Ali"
age = 17
marks = 85
print(name)
print(age)
print(marks)
output: Ali 17 85
Types of Variables
1. Integer Variable
2. Float Variable
3. String Variable
4. Boolean Variable
Advantages of Variables
 Store data easily
 Make programs flexible
 Help in calculations
 Improve readability of code

You might also like