0% found this document useful (0 votes)
20 views2 pages

Python Worksheet Answers

The document provides answers to Python worksheet questions, covering Boolean operators, iterative statements, loops, membership operators, and infinite loops. It includes examples for each concept to illustrate their usage. Key distinctions between for and while loops are also highlighted.

Uploaded by

purushottam18457
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)
20 views2 pages

Python Worksheet Answers

The document provides answers to Python worksheet questions, covering Boolean operators, iterative statements, loops, membership operators, and infinite loops. It includes examples for each concept to illustrate their usage. Key distinctions between for and while loops are also highlighted.

Uploaded by

purushottam18457
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

Python Worksheet Answers

1. Explain Boolean operators with an example.


Boolean operators combine conditions and return True or False. The main Boolean
operators are and, or, and not.

Example:

a=5

b = 10

print(a < b and b > 5)

2. What do you mean by iterative statements? Give an example.


Iterative statements repeat a block of code multiple times.

Example:

for i in range(5):

print(i)

3. Distinguish between the for and while loop.


For loop: Used when the number of repetitions is known.

While loop: Used when a loop runs based on a condition.

4. State the use of the membership operators in Python.


Membership operators check whether a value exists in a sequence such as a list or string.
The operators are 'in' and 'not in'.

Example:

x = [1, 2, 3]

print(2 in x)

5. What is an infinite loop? How is it created?


An infinite loop is a loop that runs continuously and never stops because the condition
always remains true.

Example:

while True:
print('Hello')

You might also like