The Sanskaar Valley School
Class 8 CAIE – Computer Science
Copy Work
Date: __/___/____
CHAPTER 7
INTRODUCTION TO PYTHON
Shown Introductory Video: https://www.youtube.com/watch?v=Bf-yTmq5Aow&t=141s
KEYWORDS:
Python IDLE, Python Shell, Operators (Arithmetic operators, Assignment operators, Relational Operators, Logical
Operators), variables, input(), print(), Conditional Statements, Flow of control, if statement, if -else statement,
if-elif ladder.
IDLE: A simple Integrated Development Learning Environment that comes with Python.
Variable: These are named memory locations whose value may change during the execution of the program.
Flow of Control: Show the order of execution of the statements in a program.
input(): This function is used to fetch an input from the user.
Operators:
✓ Arithmetic operators (+, -, *, ?, %, **, //)
✓ Assignment operators (=, +=, -=, *=, /=, %=, //=, **=)
✓ Relational operators (==, !=, >, <, >=, <=)
✓ Logical Operators (and, or, not)
Q1. Explain the difference between = and ==. Explain with the help of an example.
Ans: = is an assignment operator which is used to assign value to a variable whereas == is a relational operator
which is used to compare two values. The output of == operator is either True or False.
For example, x = y means assign value of y to x whereas x ==y means compare if x is equal to y or not.
Q2. How do you accept data in a variable from the user? Give the syntax of the command along with an
example.
Ans: In a variable, value can be stored in two ways. Either it can be declared in a variable within the program or
can be accepted from the user.
Syntax: input(<Prompt>)
Example:
number1 = int(input(“Enter the first number“))
number2 = int(input(“Enter the second number“))
print(number1+number2)
Q3. Write a program in Python to execute the following instructions.
1. Accept the length and the breadth of a rectangle from the user and calculate its area and perimeter.
length = int(input(“Enter the length of rectangle”))
breadth = int(input(“Enter the breadth of rectangle”))
area = length * breadth
perimeter = 2*(length + breadth)
print(“The area of rectangle is : “, area)
print(“The perimeter of rectangle is: “, perimeter)
2. Accept three numbers from the user and display the largest number.
number1 = int(input(“Enter the first number“))
number2 = int(input(“Enter the second number“))
number3 = int(input(“Enter the third number“))
if number1>number2 and number1>number3:
print(“The highest is: “, number1)
elif number2>number1 and number2>number3:
print(“The highest is: “, number2)
else:
print(“The highest is: “, number3)
3. Accept a number from the user and check if it is an odd number or even number.
number = int(input(“Enter the number”))
modulus = number%2
if modulus == 0:
print(“The number is even“)
else:
print(“Odd number“)
Do lab work and project work given on page no 134 and 135 of textbook.