DELHI PUBLIC SCHOOL
NACHARAM
SUBJECT: COMPUTER LS 2 Control Statements in Python CLASS VII
D. Answer the following questions:
1. What is the difference between '/' and'//' operator?
Ans.
Division (/) Floor Division (//)
Division operator is used to divide the Floor division operator is used to divide the
numbers and give an output in the decimal numbers and give an output in an integer form.
form. eg: Value of 5/2 is 2.5 eg: Value of 5//2 is 2
2. What is the use of '*' operator in string manipulation?
Ans. ‘*’ Operator is used to replicate a given string for a specified number of times. It is also
known as a replication operator.
eg: print ('python'*3)
Output: pythonpythonpython
3. Define operators. Also, name the different types of operators.
Ans. Operators are symbols that perform arithmetic, logical and relational operations on
operands and provide a meaningful result.
Types of operators are: Arithmetic operators, String operators, Assignment operators,
Relational operators and logical/boolean operators.
4. Distinguish between logical and relational operators.
Ans.
Relational Operators Logical or Boolean operators
Relational operators are used to show the Logical or Boolean operators evaluate the
relationship between operands. expression.
They compare the values of the variables They combine the results of two or more
relational expressions.
5. What are control Statements? List the different types of control Statements
Ans. Control statements are used to control the flow of the execution of the loop based on a
condition.
In python there are 3 different types of control structures:
1. Sequential statements
2. Conditional Statements
3. Iterative statements
6. Describe the use of conditional statements.
Ans. Conditional statements are used to control the flow of a program based on certain
conditions. These statements allow the execution of different code blocks depending on whether
a specified condition evaluates to true or false.
7. Write the syntax of if-else statement.
Ans. Syntax:
if <condition>:
statement set 1
else:
statement set 2
LAB SESSION
A. Write the output of the following code segments in the space provided.
1 a=10 False
b=20
print(a>10 and b<40)
2 a=10 30
b=20 a+b
print(a+b)
print(‘a+b’)
3 a=100 100 is a three digit
if a>99: number
print(a, ‘is a three digit number’)
else:
print(a,’is a two digit number’)
4 a=4 4 is even number
if a%2 = = 0 :
print(a, ‘is even number’)
else:
print(a,’is odd number’)
B. Rewrite the programs after correcting the errors in the space provided.
1 n=6 n=6
if n%2 = = 0:
If N%2 = 0: print (n, “is divisible by 2”)
Print “n, is divisible by 2”
2 a=10,b=20 a=10,b=20
Sum = a + b sum = a + b
Print(Sum of numbers is +sum)) print(“Sum of numbers is “, sum)
3 num1=50 num1=50
Num2=60 Num2=60
If Num1 < Num2 if (num1 < Num2):
Print num1 is smaller than Num2 print(num1,”is smaller than”,Num2)
Else else:
Print Num2, is greater than print(Num2,”is greater than”,num1)
Num1
My Activity (Page No. 38)
Write the code for the following programs in the Script mode:
1.Using the String Replication operator, print your name 10 times
Ans: print(‘Delhi Public School \n’ * 10)
2. Input your marks of five subjects. Calculate the percentage and find your grade
according to the following conditions:
● If the percentage is greater than or equal to 90, the grade is “A”
● If the percentage is between 80 and 89, the grade is “B”
● If the percentage is between 70 and 79, the grade is “C”
● If the percentage is between 60 and 69, the grade is “D”
● If none of the above conditions are met, the grade is “E”.
English = float(input("Enter marks for English subject "))
Maths= float(input("Enter marks for Maths subject "))
Science = float(input("Enter marks for Science subject "))
Social = float(input("Enter marks for Social subject "))
Language=float(input("Enter marks for Language subject "))
total_marks = English+Maths+Science+Social+Language
per = (total_marks / 500) * 100
if per >= 90:
print(“Grade A”)
elif per>=80 and per < 90:
print(“Grade B”)
elif per>=70 and per < 80:
print(“Grade C”)
elif per>=60 and per < 70:
print(“Grade D”)
else:
print(“Grade E”)
3. Simulate a shopping scenario. Input the total amount of purchase and calculate the
discount according to the given conditions. Then, find the net payable price after deducting
the discount from the total amount of purchase.
● If the total amount is greater than or equal to 10000, a 15% discount is applied.
● If the total amount is less than 10000 and greater than 5000, a 10% discount is
applied.
● If the total amount is less than 5000, no discount is applied.
total_amount = float(input("Enter the total amount of purchase: "))
if total_amount >= 10000:
discount = total_amount * 0.15
print(“15% discount is applied. Net payable price”, total_amount - discount)
elif total_amount> 5000 and total_amount < 10000:
discount = total_amount * 0.10
print(“10% discount is applied. Net payable price”, total_amount - discount)
else:
discount = 0
print(“no discount is applied.Net payable price”, total_amount-discount)
4. Create a program to find if a year is a leap year or not. A year is a leap year if it is
divisible by 4
year= int(input('Enter a year \n'))
if ((year % 4) == 0) :
print(year ,'is a leap year')
else:
print(year, ' is not a leap year')
5. Write a program to display “Eligible for licence”. If the condition “age of the person
should be >=18” is true.
age=int(input(‘enter your age’))
if(age >=18):
print(‘Eligible for licence’)
else:
print(‘Not eligible for licence’)
Extra Program:
1 Input two numbers and design a program which can perform the following arithmetic
functions:
a= int(input(“enter first number =\n'')) Output:
b= int(input(“enter Second number=\n”)) enter first number=
print('sum is: ',a+b) 40
print('difference is: ',a-b) enter Second number=
print('remainder is: ',a%b) 30
print('quotient is: ', a/b) sum is: 70
print('floor division is: ', a//b) difference is: 10
print('product is: ', a*b) remainder is: 10
quotient is: 1. 33
floor division is: 1
product is: 1200
Project Work
Input the name, age and basic salary of an employee. Calculate the total salary of an
employee by adding 10% DA and 10% HRA to the basic salary
E_name=input(“Enter Employee Name:”) Output:
age=int(input(“Enter Age of the Enter Employee Name: RAKSH
Employee:”)) Enter Age of the Employee: 23
BSal = int(input(“Enter the Basic Salary of Enter the Basic Salary of the employee: 25000
the employee:”))
DA= BSal * (10/100) The total salary of the employee is : 30000
HRA=BSal * (10/100)
TSal = BSal+DA+HRA
print(“The total salary of the employee is:”,
TSal)