0% found this document useful (0 votes)
5 views

Python_Grade 7

Uploaded by

nisha.kawale
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python_Grade 7

Uploaded by

nisha.kawale
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python: Conditions and loops

Q.1 Fill in the blanks.

a. If b=0, the output of b!=0 will be False.

b. The and logical operator gives true only when both logical tests are true.

c. The logical operator statement allows you to handle multiple conditions.

d. A loop that does not end is called an infinite loop.

e. The continue statement is used to skip the current iteration of a loop and move to the
next iteration.

Q.2 Answer the following questions.

a. Explain the purpose of an “else” statement in Python’s “if” statement.

Ans- The if….else statement allows you to execute different blocks of code based on whether a
condition is true or false. The ‘else ‘ statement is used to execute the code inside it, if the
condition specified is false.

b. What is the purpose of the “pass” statement in Python.

Ans-The pass statement is used to skip over some code for a specific reason. It is a way to tell
the computer to do nothing the computer has to ignore it and move to the next instruction.

c. What is the difference between a ‘while’ and a ‘for’ loop?

Ans-the ‘while’ loop allows to repeat a set of instructions as long as a specific condition remains
true.

The ‘for’ loop is used when we need to repeat the same instructions for each value in a
sequence.

d. Ishaan wants to print the multiplication table of a number using a loop. Which loop will he
select for the same and why?

Ans- The ‘for’ loop is suitable to print the multiplication table of a number because for loop is
suitable to repeat the instruction for each value of a number in table.

e. What is the use of logical operators? Explain with an example.


Ans- Logical operators are used to combine multiple conditions and determine the overall
result.
Example: x=12
Y=10
(x>0 and y<20)
It will print result as True.

Q.3 What will be the output of the following programs in Python?

Ans-
10
7
4
1

Ans-
1
3
4
5
Ans- x is equal to or less than 5

You might also like