Page 36 - 2501_KVS_C-7
P. 36
Activity 3.1
1. Write a Python program to calculate the perimeter of a square whose side is 7 cm.
2. Write a Python program to calculate the perimeter of a rectangle whose length is
9 cm and whose breadth is 3 cm.
3. Write a Python program to display the area of a circle with radius 4 cm.
(Hint: area = 3.14 × radius × radius).
4. Write a Python program to calculate simple interest on a principal amount of 5 000
for a period of 3 years at an interest rate of 5 %.
3.2 PYTHON PROGRAMMING – DECISION STRUCTURE
3.2.1 Inputting Values
Dear students, you learnt about programming basics and development of program in the
previous chapter. You know each program may consist of input, process and output. In the
previous chapter, programs generated output on the basis of fixed values.
Example 1: Program to find sum of A and B.
A=5
B=6
S=A+B
print("Sum of A and B is ", S)
You will get output as: Sum of A and B is 11
In this example, you will always get the same output on execution of program, because the
values of A and B are fixed.
Can you give value of A and B at the time of execution of program? Yes, you can give values
of A and B at run-time. To input values at run-time, you use the input() function.
Syntax: variable = input("message")
Program 1: Write a program to display a message Code:
received from user. msg=input("Give your message:")
In this program, whatever message will be given print(msg)
by the user will be displayed by a print statement.
Program 2: Write a program to input the age of a
person and display age increased by 2 year. Code:
Always returns a string, but you are trying to age=input("Enter your age")
add the number 2 to it. Python raises TypeError age=age+2
because you cannot add a string and an integer print(age)
directly.
34 KVS DELHI REGION 2025

