PART A
1) Write a python program to interchange the values of two variables using the
third variable.
Flowchart:
Program:
a=int(input("Enter first number: "))
b=int(input("Enter second number:”))
print("Before interchanging")
print("value of a =", a)
print("value of b =", b)
temp=a
a=b
b=temp
print("After interchanging")
print("value of a =", a)
print("value of b =", b)
2) Write a python program to input two numbers and perform all arithmetic
operations on them.
Flowchart:
Program:
a=int(input("Enter first number : "))
b=int(input("Enter second number : "))
s=a+b
d=a-b
p=a*b
q1=a/b
q2=a//b
r=a%b
print("printing the result of all arithmetic operations")
print("Addition =",s)
print("Subtraction=",d)
print("Multiplication=",p)
print("Division =", q1)
print("Quotient =", q2)
print("Remainder =", r)
3) Write a python program to input length and width of a rectangle and find its
area and perimeter.
Flowchart:
Program:
l=float(input("Enter the length : "))
w=float(input("Enter the width : "))
area=l*w
perimeter=2*(l+w)
print("area of rectangle=", area)
print(" perimeter of rectangle=",perimeter)
4) Write a python program to calculate the amount payable if money has lent
on simple interest by accepting the inputs principal amount P, Time T and
rate of interest R.
Flowchart:
Program:
p=int(input("Enter principle amount : "))
t=int(input("Enter time period : "))
r=int(input("Enter rate of interest : "))
si=(p*t*r)/100
ap=p+si
print(“simple interest=”,si)
print("amount payable=",ap)
5) Write a python program to find largest among 3 numbers.
Flowchart:
Program:
a=int(input("Enter first number : "))
b=int(input("Enter second number : "))
c=int(input("Enter third number : "))
big=a
if (b>big):
big=b
if(c>big):
big=c
print(“Largest Number=”,big)
6.Write a python program that takes the name and age of the user
as input and displays a message whether the user is eligible to
apply for a driving license or not. (The eligible age is 18 years).
Flowchart:
name=(input("Enter the name : "))
age=int(input("Enter the age : "))
if age>=18:
print(" name=", name)
print(" He is eligible for driving license")
else :
print("name=", name)
print("He is not eligible for driving license")
7.Write a python program to find the minimum and maximum of
five numbers entered by the user.
Flowchart:
numlist=[int(input("Enter the number: "))for i in range(5)]
largest=smallest=numlist[1]
for i in numlist:
if i<smallest:
smallest=i
if i >largest:
largest=i
print("The smallest number is", smallest)
print("The largest number is ",largest)
8.Write a program to find the grade of a student when grades are
allocated as given in the table below. Percentage of Marks Grade
Above 90% A,80% to 90% B,70% to 80% C, 60% to 70% D Below 60%
E Percentage of the marks obtained by the student is input to the
program.
Flowchart:
perc=int(input("Enter the student percentage : "))
if(perc>90):
print("grade= A")
elif(perc>=80 and perc<90):
print("grade= B")
elif(perc>=70 and perc<80):
print("grade= C")
elif(perc>=60 and perc<70):
print("grade= D")
else:
print("grade= E")
9.Write a function to print the table of a given number. The number
has to be entered by the user.
Flowchart:
number = int(input ("Enter the number print the multiplication
table:"))
print ("The Multiplication Table of: ", number)
for count in range(1, 11):
print (number, 'x', count, '=', number * count)
10.Write a program to find the sum of digits of an integer number,
input by the user.
Flowchart:
num=int(input("Enter number"))
sum = 0
while (num != 0):
r = num % 10
sum = sum + r
num = num // 10)
print(sum)
11. Write a program to check whether an input number is a
palindrome or not.
Flowchart:
PROGRAM:
num=int(input("Enter number:"))
temp=num
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
12. Write a program to print the following patterns:
12345
1234
123
12
1
rows = 5
for i in range(rows,0,-1):
for j in range(1, i + 1):
print(j,end=" ")
print('\r')
*****************