TET’s
GLOBAL ACHIEVERS SCHOOL
GRADE – MASTER COPY SUBJECT-
************************************************************************************************
UNIT: - 4
Activity (Page no 72)
1. Write a program to enter age and check if the citizen is senior or not.
Ans: age = int (input ("enter your age"))
if (age>=60):
else:
print ("You are a senior citizen")
print ("You are not a senior citizen")
2. Write a program to enter two values and print square of greater number.
Ans: num1 = int (input ("enter number"))
num2 = int (input ("enter another number"))
if (num1>num2):
print (num1*num1)
elif (num2>num1):
else:
print (num2*num2)
print ("both the numbers are equal")
3. Write a program to check whether a citizen is child, adolescent, middle age or senior.
Ans: age=int (input ("enter your age"))
(age<=11):
print ("You are a child")
elif (age<=18):
print ("You are an adolescent")
elif (age<=59):
else:
print ("You are a middle age")
print ("You are a senior")
(A) Fill in the blanks with the help of the hints.
1. Intel, Cisco, Seagate, Qualcomm, and IBM use Python for hardware testing
2. The if statement will execute block of statements only if the condition is true.
3. A Loop statement allows us to execute a statement or group of statements multiple times.
4. float() function is used to convert input into floating point numbers.
(B) Tick (✔) the correct answer.
1. Which statement will print "Hello World" in Python?
a) print("Hello world") b) p("Hello world") c) echo " hello world"
2. What is the correct file extension for Python files?
a).pyth b).pyt c).py
[Link] operator can be used to compare two values?
a) < > b) == c) <=
4. How do we write an if statement in Python?
a) if(x>y)then: b) if(x>y) c) if x>y:
[Link] whether these statements are True or False. Correct the False statements also.
1. Syntax of range() Function is: range(step, stop, start).
False. Syntax of range() Function in range (start, stop, step).
2. To check another condition when first condition is false, elif is used. True
[Link] for Loop executes a block of code repeatedly till the condition is true. True
D. Answer the following questions.
1. List the key features of Python.
i. Python is easy to understand and learn for beginners.
ii. Python interpreters are available for many operating systems.
iii. Python is a multi-paradigm programming language. (Procedural and Object-oriented)
iv. Its formatting is visually uncluttered, and it often uses English keywords.
v. The simple and easy-to-learn syntax of Python emphasises readability.
vi. It supports modules and packages, which encourages program modularity and code reuse.
vii. It can be easily integrated with languages like C, C++, Java etc.
2. What are iteration statements in Python? Define each one of them.
Ans: Iteration or loop statement in python are used to repeat steps till the condition is true. Python has two
iteration statement: for and while.
i. for loop: The for loop is used when the number of repetitions is pre-known. It is also known as definite loop.
ii. while loop: The while loop is used when the number of repetitions is not known and are based on a
condition. The loop repeats till the condition is true.
3. Describe the different types of decision making statements available in Python.
Ans. i) if statement : The if statement is a flow control statement used to check a condition. If the condition is
true, the following statement(s) are executed.
Syntax: if condition:
statements
ii) if...else statement: The if else statements will execute one block of statements if the condition is true
and another block of statements will be executed if the condition is false.
Syntax: if condition:
statements_if_true
else:
statements_if_false
iii) Nested if statement: A nested if statement means having one if statement inside another. It is used to check
multiple conditions one after another.
Syntax : if condition1:
if condition2:
statements
iv. elif statement: elif is used to check multiple conditions when the previous if condition is false. If
none are true, the else block runs. It’s like else if in other languages.
Syntax: if condition1:
statements
elif condition2:
statements
else:
statements
4. How is a .pyc file different from a .py file?
Ans. .py = A Python program file is saved with extension .py
.pyc= This is a compiled bytecode file automatically created by Python when a .py file is executed.
It helps the program run faster next time.
E. Answer in short.
1. Is Python case-sensitive?
Ans. Yes, Python is case-sensitive language.
2. How is Python an interpreter language?
Ans .Once compiled, a Python program file is saved as byte using Python Virtual Machines. Thus, Python is an
code. This byte code is interpreted to execute program interpreter language.
[Link] is the significance of indentation in python?
Ans. Python use indentation (whitespace at the beginning of languages often use curly-brackets for this purpose. a line)
to define scope in the code. Other programming
[Link] does nested if and elif differ in python?
Ans. Nested if is used when we have to check another condition when the first condition is true. An elif is used when
another condition has to be checked when the first condition is false.
5. What does the "in" operator do?
Ans. A list or sequence has to be defined to use a for loop in Python. The membership operator 'in' checks whether a
value is present in a list or not. The loop will continue to execute for all the values present in the list. The loop
will stop at the end of the list.
Example: Program to print a list
x=8
For x in [8, 9, 10, 12]:
Print (x)
F) Application based questions
1. Without using the interpreter, tell us how many times will Python execute the code inside the following while loop?
i=0
while i < 2:
print "Hello..."
i=i+1
Two times