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

Python Unit1 Notes QA Format

The document provides a Q&A format overview of Python's conditional statements and looping constructs. It explains 'if', 'if-else', 'elif', nested if statements, while loops, for loops, and the use of 'break' and 'continue' in loops. Additionally, it covers the concept of nested loops with examples for each topic.

Uploaded by

drdoom4922
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)
2 views3 pages

Python Unit1 Notes QA Format

The document provides a Q&A format overview of Python's conditional statements and looping constructs. It explains 'if', 'if-else', 'elif', nested if statements, while loops, for loops, and the use of 'break' and 'continue' in loops. Additionally, it covers the concept of nested loops with examples for each topic.

Uploaded by

drdoom4922
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/ 3

Python Unit 1: Conditional Statements and Looping (Q&A Format)

1. What is an 'if' statement in Python?

The 'if' statement is used to check a condition. If the condition is true, the block of code under it will

run.

Example:

if x > 0:

print("Positive")

2. What is an 'if-else' statement?

The 'if-else' statement runs one block if the condition is true, and another block if it is false.

Example:

if x > 0:

print("Positive")

else:

print("Not Positive")

3. What is an 'elif' statement?

'elif' means 'else if'. It is used to check multiple conditions one by one.

Example:

if x > 0:

print("Positive")

elif x == 0:

print("Zero")

else:

print("Negative")

4. What is a nested if statement?

A nested if is an if statement inside another if block.

Example:
if x >= 0:

if x == 0:

print("Zero")

else:

print("Positive")

5. What is a while loop?

A while loop repeats a block of code as long as the condition is true.

Example:

i=1

while i <= 5:

print(i)

i += 1

6. What is a for loop?

A for loop is used to iterate over a sequence (like a list or range).

Example:

for i in range(5):

print(i)

7. What does 'break' do in a loop?

'break' is used to exit the loop early.

Example:

for i in range(10):

if i == 5:

break

print(i)

8. What does 'continue' do in a loop?

'continue' skips the current iteration and continues with the next one.
Example:

for i in range(5):

if i == 2:

continue

print(i)

9. What is a nested loop?

A nested loop is a loop inside another loop.

Example:

for i in range(2):

for j in range(2):

print(i, j)

You might also like