Practical Programs
Practical Programs
9. WRITE THE SOURCE CODE CORRECTLY AND USE PROPER INDENDATION AS GIVEN IN THE
SOURCE CODE.
PRACTICAL PROGRAMS
Source Code :
c=a+b
d=a-b
e=a*b
f=a/b
g= a%b
h= a**2
Output :
Added result is : 30
Subtracted result is : 20
Remainder result is : 0
Aim : To find the simple interest for the given Principle, No of years and Rate of interest
Source Code:
Output :
Enter No of Years : 5
Source Code :
a,b=b,a
OUTPUT:
Enter a number : 75
Aim : To check the mark and print PASS / FAIL using if else statement
Source Code :
if m>=40:
else:
OUTPUT
Enter mark : 75
Enter mark : 23
Aim : To find the given year is leap year or not using if..else statement
Source Code :
if y % 4 == 0:
else:
Output
AIM : Program to check whether a given number is odd or even using if… else
statement.
Source Code :
else:
Output :
56 is a even number
95 is a odd number
Program 7 : Write a program to print multiplication table
Source Code :
i=1
i = i +1
Output
7*1=7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70
Program 8: Write a program to print first n add and even natural numbers
Source Code:
for i in range(1,x+1,2):
print(i)
for i in range(2,x+1,2):
print(i)
Output
10
Program 9 Akash wants to create a password based smart system for the entry door
Write a code which can take password as an input from the user and then check for the
correct password which is "SECRET". The user can enter the password only 3 times
and the system should print "You cannot enter the house after that".
AIM : Writing a program to check for the password using looping and selection
statement.
Source code :
flag = 0
for i in range(3):
if pwd == "SECRET":
print("Welcome!")
flag = 1
break
else:
if flag == 0:
OUTPUT :
Wrong password!
Wrong password
Program 10 : Write program to find the factorial of a number
Source Code:
#FACTORIAL OF A NUMBER
s=1
for i in range(1,x+1,1):
s=s*i
Output
Aim: Program to check a given number is positive , negative or zero using if else ladder
Source Code:
if a>0:
elif a<0:
else:
Output
5 is a postive number
-5 is a negative number
*
**
***
****
*****
Aim : Program to print the pattern.
Source Code
for i in range(1,x+1,1):
for j in range(1,i+1,1):
print("*",end=' ')
print("\n")
Output
**
***
****
*****
Program 13 : Write a program to find the area and circumference of a circle
Source Code:
p = 2 * 22/7 * r
output
Source Code
reversed_num = 0
while num != 0:
digit = num % 10
num //= 10
Output :
Aim : Program to print day name in words using if elif else ladder
Source Code
if day == 1:
elif day == 2:
elif day == 3:
elif day == 4:
elif day == 5:
elif day == 6:
elif day == 7:
else:
OUTPUT :
4 is Wednesday