Computer Science – Python Class 7 – Very able Variables, If you think for a while – Practise Set 2 Answer Key

1. Boolean (bool) data type stores True or False values.


2. The list data type is used to store multiple values in a single variable (a collection of items).


3. The process is called decision-making / conditional execution.


4. Invalid variable name: c. roll.no (dot . is not allowed in variable names).


5. An if statement can have one block of code (but can be extended with elif and else).


6.
a. Logical operator or is used.
b. A person can travel if either of the two conditions is true – having a ticket or paying cash.


7.

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a > b:
    print("Greater number is:", a)
else:
    print("Greater number is:", b)

8.
A nested if statement means using one if statement inside another.

Example:

num = int(input("Enter a number: "))
if num > 0:
    if num % 2 == 0:
        print("Positive even number")
    else:
        print("Positive odd number")

9.
a. Converting a string to integer:

int("123")

b. Finding the length of a string:

len("hello")

10.
a. % → Modulus operator, gives remainder. Example: 10 % 3 = 1
b. < → Less than operator, checks if left value is smaller. Example: 4 < 7 = True

Leave a Reply

Discover more from Abhyas

Subscribe now to keep reading and get access to the full archive.

Continue reading