Class11 Listofprograms
Class11 Listofprograms
Vidyalaya, Tirupati
Class : XI Python Practical Record Programs
INDEX
Commands:
>>> 6*3 >>> a=8%3
18 >>> a
>>> 3**3 2
27 >>> a=8//3
>>> 6+2*4 >>> a
14 2
>>> 5-3-3 >>> 3**2**0
-1 3
>>> 9.0**0.5 >>> 9.0%3
3.0 0.0
>>> (5+3.1)*5 >>> -9.0%3
40.5 0.0
>>> s=5.0-(3-3.0) >>> 3<5 and 5<3
>>> s False
5.0 >>> 3<=3
>>> x=12.0/4 True
>>> x >>> 3+(8*9/3)
3.0 27.0
>>> 7--7--7 >>> 12+3*4-6/2
21 21.0
>>> 8/6 >>> 12%3**4//5+6
1.3333333333333333 8
Task-2
Write Python expressions equivalent to the following arithmetic /
algebraic expressions and evaluate the output.
1 ab 6 * sum
a. ut+ at2 b. c. 8-6+ - var
2 2 7
Aim:
To Write Python expressions equivalent to the following
arithmetic/algebraic expressions
Source Code:
1
a. ut+ at2 = (u * t) + (1/2) * a * t ** 2
2
ab
b. = (a + b ) /2
2
6 * sum
c. 8-6+ - var = 8-6 + (6* sum) / 7 – var ** 1/2
7
Task-3
Write a program in Python which accepts two integers x and
n, compute xn.
Aim:
To write a program in Python which accepts two integers and x
and n, compute xn
Source Code:
# Program to compute xn
x=int(input("Enter the value of x"))
n=int(input("Enter the value of n"))
p=x**n
print("pow(x,n)=",p)
Conclusion:
The above program was executed successfully
Task-4
Write a program in Python to calculate Simple Interest
( Use formula si = PTR/100 )
Aim:
To write a program in Python to calculate Simple Interest
Source Code:
# Program to Calculate Simple Interest
principal=float(input("Enter the principal amount:"))
time=int(input("Enter the time(years):"))
rate=float(input("Enter the rate:"))
simple_interest=(principal*time*rate)/100
print("The simple interest is:",simple_interest)
Conclusion:
The above program was executed successfully
Task-5
Write a program in Python to calculate Compound Interest
( Use the formula A=P(1+r/100)n and ci=A-P )
Aim:
To write a program in Python to calculate Compound Interest
Source Code:
# Program to calculate Compound Interest
principal=float(input("Enter the principal amount:"))
time=int(input("Enter the time(years):"))
rate=float(input("Enter the rate:"))
A = principal * (1 + rate/100) ** time
CI = A - principal
print("compound interest = ", CI)
Conclusion:
The above program was executed successfully
Task-6
Write a program in Python to calculate Area of a Triangle for
the given three sides.
Aim:
To write a program in Python to calculate Area of a Triangle
Source Code:
# Python Program to find Area of a Triangle
Conclusion:
The above program was executed successfully
Task-7
Write a program in Python to convert Fahrenheit to Celsius
and Celsius to Fahrenheit
Aim:
To Write a program in Python to convert Fahrenheit to Celsius and
Celsius to Fahrenheit
Source Code:
#Fahrenheit to Celsius
f=float(input("Enter temperature in Fahrenheit :"))
c=(f-32)*5/9
print("\nTemperature in Celsius is ",round(c,2))
#Celsius to Fahrenheit
c=float(input("\nEnter temperature in Celsius :"))
f=c*9/5 +32
print("\nTemperature in Fahrenheit is ",round(f,2))
Conclusion:
The above Python program was executed successfully
Task-8
Write a program in Python to swap two numbers using a
temporary variable (third variable)
Aim:
To Write a program in Python to swap two numbers using a
temporary variable (third variable)
Source Code:
Conclusion:
The above Python program was executed successfully
Task-9
Write a program in Python to swap two numbers without
numbers using a temporary variable (third variable)
Aim:
To Write a program in Python to swap two numbers without using
a temporary variable (third variable)
Source Code:
Conclusion:
The above Python program was executed successfully
Task-10
Aim:
To Write a program in Python to find the diameter, Area and
Circumference of a Circle.
Source Code:
# Python Program to find the diameter, Area and the
circumference of a Circle
PI = 3.14
radius = float(input(' Enter the radius of a circle: '))
diameter = 2 * radius
circumference = 2 * PI * radius
area = PI * radius * radius
print(" \nDiameter of the Circle = " ,diameter)
print(" Circumference of the Circle =", circumference)
print(" Area of the Circle = " ,area)
Conclusion:
The above Python program was executed successfully
Task-11
Aim:
To write a program in Python to find the biggest of two numbers
using elif statement.
Source Code:
# Python Program to find the Biggest of Two Numbers
a = float(input(" Enter the First number: "))
b = float(input(" Enter the Second number: "))
if(a > b):
print( a ,” is Greater than “, b)
elif(b > a):
print( b,” is Greater than “,a)
else:
print("Both the numbers are Equal")
Conclusion:
The above Python program was executed successfully
Task-12
Write a program in Python to check whether a person is
eligible to vote or not
Aim:
To Write a program in Python to check whether a person is eligible
to vote or not
Source Code:
#Program to check vote eligibility
age=int(input("Enter the age:"))
if age>=18:
print(" Person is eligible to vote")
else:
print(" Person is not eligible to vote")
Conclusion:
The above Python program was executed successfully
Task-13
Write a program in Python to check whether a number is odd
or even
Aim:
To Write a program in Python to check whether a number is odd or
even
Source Code:
#Program to check Odd or Even
num=int(input("Enter the number :"))
if num%2==0:
else:
Conclusion:
The above Python program was executed successfully
Task-14
Write a program in Python to design a Simple Calculator by
using numbers
Aim:
To Write a program in Python to design a Simple Calculator by
using numbers
Source Code:
#Simple Calculator
n=int(input("Enter first number : "))
m=int(input("Enter second number : "))
print(" Press 1 for Addition")
print(" Press 2 for Subtraction")
print(" Press 3 for Multiplication")
print(" Press 4 for Division")
print(" Press 5 for Floor Division")
print(" Press 6 for Remainder\n")
ch=int(input("Enter your choice"))
if ch==1:
print("Addition of two numbers is ", n+m)
elif ch==2:
print("Subtraction of two numbers is ",n-m)
elif ch==3:
print("Product of two numbers is ",n*m)
elif ch==4:
print("Division of two numbers is ",n/m)
elif ch==5:
print("Floor division is ",n//m)
elif ch==6:
print("Remainder of division is ",n%m)
else:
print("Invalid choice")
Aim:
To Write a program in Python to design a Simple Calculator by
using Arithmetic Operators (Symbols).
Source Code:
#SIMPLE CALCULATOR
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
print("Select any one operator: +,-,*,/,%,// ")
c=input("Enter the symbol:")
if c=='+':
print(a+b)
elif c=='-':
print(a-b)
elif c=='*':
print(a*b)
elif c=='/':
print(a/b)
elif c=='%':
print(a%b)
elif c=='//':
print(a//b)
else:
print("invalid")
Conclusion:
The above Python program was executed successfully
Task-16
Write a program in Python to generate Student Progress
Report.
Aim:
To Write a program in Python to generate Student Progress
Report
Source Code:
Enter name:Virat
Enter English marks:67
Enter Computer Science marks:78
Enter Physics marks:67
Enter Chemistry marks:86
Enter Biology marks:91
------------------------------
Student Report
------------------------------
Name : Virat
Total : 389
Percent : 77.8
Grade : B
------------------------------
Conclusion:
The above Python program was executed successfully
Task-17
Write a program in Python to generate Electricity bill for the
given data.
Aim:
To Write a program in Python to generate Electricity bill for the
given data
Source Code:
Conclusion:
The above Python program was executed successfully
Task-18
Write a program in Python to find the Biggest of three
numbers using if..elif ..else statement.
Aim:
To write a program in Python to find the Biggest of three numbers
using if..elif..else statement.
Source Code:
a = float(input("Please Enter the first number: "))
b = float(input("Please Enter the second number: "))
c = float(input("Please Enter the third number: "))
if (a > b and a > c):
print(a," is Greater Than", b," and",c)
elif (b > a and b > c):
print(b," is Greater Than", a," and",c)
elif (c > a and c > b):
print(c," is Greater Than", a," and",b)
else:
print("Either any two values or all the three values are equal")
Conclusion:
The above Python program was executed successfully
Task-19
Write a program in Python to display first ‘n’ odd and even
numbers
Aim:
To write a program in Python to display first ‘n’ odd and even
numbers
Source Code:
#program to print first n odd numbers
n=int(input("Enter total number:"))
c=0
i=1
print("First ",n,"odd numbers are")
while c<n:
print(i)
c=c+1
i=i+2
Source Code:
n=int(input("Enter table number:"))
for i in range(1,11):
print(n, "x", i , '=' , n*i)
Conclusion:
The above Python program was executed successfully
Task-21
Write a program in Python to find the factorial of a given
number
Aim:
To write a program in Python to find the factorial of a given
number.
Source Code:
#Program to find the factorial of a given number
n=int(input("Enter the number:"))
f=1
for i in range(1,n+1):
f=f*i
print("The factorial of given number is ",f)
Conclusion:
The above Python program was executed successfully
Task-22
Write a program in Python to reverse a given number
Aim:
To write a program in Python to reverse a given number.
Source Code:
#Program to reverse a given number
n=int(input("Enter the number:"))
rev=0
while n>0:
r=n%10
rev=rev*10+r
n=n//10
print("The reverse of the given number is ",rev)
Conclusion:
The above Python program was executed successfully
Task-23
Write a program in Python to check if a given number is
Palindrome or not.
Aim:
To write a program in Python to check if a given number is
Palindrome or not
Source Code:
#Program to check if given number is palindrome
n=int(input("Enter the number:"))
num=n
rev=0
while n>0:
r=n%10
rev=rev*10+r
n=n//10
if rev==num:
print("The given number is a palindrome")
else:
print("The given number is not a palindrome")
Conclusion:
The above Python program was executed successfully
Task-25
Write a program in Python to find the square of a given
number
Aim:
To write a program in Python to find the square of a given number
Source Code:
#Program to find the Square of a number
#Method-1
num=int(input("Enter the number:"))
numsq=num**2
print("The square of the given number is",numsq)
#Method-2
numsq=pow(num,2)
print("The square of the given number is",numsq)
Conclusion:
The above Python program was executed successfully
Task-25
Write a program in Python to find the sum of ‘n’ terms
Aim:
To write a program in Python to find the sum of ‘n’ terms
Source Code:
Conclusion:
The above Python program was executed successfully
Task-26:
Write a program in Python to generate the following patterns
(Floyds triangle) using nested loops.
Aim:
Source Code:
n=int(input("No of rows:"))
for i in range(1,n+1):
for j in range(i):
print()
Sample output:
No of rows:4
**
***
****
n=int(input("No of rows:"))
for i in range(n,0,-1):
for j in range(1,i+1):
print()
Sample output:
No of rows: 4
1234
123
12
n=int(input("No of rows:"))
for j in range(65,65+i):
print()
Sample output:
No of rows:4
AB
ABC
A BCD
Conclusion:
The above Python program for generating the Floyds triangle was
executed successfully
Task-27
Write a program in Python to input the value of x and n and print
the sum of the given series.
Aim:
To write a program in python to input the value of x and n and print the
sum of the given series.
Source Code:
sum=1
for i in range(1,n):
sum=sum+x**i
print(1,x,x*x,"...",x**(n-1),"is",sum)
Sample output:
n=int(input("Enter no of terms:"))
sum=1
j=-1
for i in range(1,n):
sum=sum+(x**i)*j
j=-j
print(1,-x,x*x,"...",-j*x**(n-1),"is",sum)
Sample output:
Enter no of term:6
sum=0
for i in range(1,n+1):
sum=sum+x**i/i
Sample Output:
Enter no of terms: 4
Conclusion:
The above Python program for finding the sum of the series for the
given ‘x’ and ‘n’ values was executed successfully
Task-28
Write a program in Python to determine whether a number is
Aim:
Source Code:
Conclusion:
The above Python program was executed successfully
Task-29
Write a program in Python to determine whether the given number
is a prime or a composite number.
Aim:
To write a program in python to check if the given number is a prime or a
composite number.
Source Code:
#Program to check if the number is a prime or composite number.
num = int(input("Enter any number : "))
if num > 1:
for i in range(2, num//2+1):
if (num % i) == 0:
print(num, "is a COMPOSITE number")
break
else:
print(num, "is a PRIME number")
elif num == 0 or 1:
print(num, "is neither a Prime nor a Composite number")
else:
print()
Sample output:
Enter any number : 23
23 is a PRIME number
Conclusion:
The above Python program was executed successfully
Task-30
Write a program in Python to display the ‘n’ terms of a Fibonacci
series.
Aim:
To write a program in Python to display the terms of a Fibonacci series.
Source Code:
# Program to display the Fibonacci sequence up to nth term
nterms = int(input("How many terms ? "))
n1, n2 = 0, 1
count = 0
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
Sample output:
How many terms ? 6
Fibonacci sequence:
0
1
1
2
3
5
Conclusion:
The above Python program was executed successfully
Task-31
Write a program in Python to compute the greatest common
divisor(GCD) and least common multiple (LCM) of two integers
Aim:
To write a program in Python to compute the greatest common divisor
and least common multiple of two integers
Source Code:
#Program to compute GCD of two numbers
num1 = int(input("Enter 1st number: "))
num2 = int(input("Enter 2nd number: "))
i=1
while(i <= num1 and i <= num2):
if(num1 % i == 0 and num2 % i == 0):
gcd = i
i=i+1
print("GCD of two numbers is ", gcd)
Sample Output:
Enter 1st number: 15
Enter 2nd number: 18
GCD of two numbers is 3
LCM of two numbers is 90
Conclusion:
The above Python program was executed successfully
Task-32:
Write a program in Python to count and display the number of
vowels, consonants, uppercase, lowercase characters in a string
Aim:
To write a program in Python to count and display the number of vowels,
consonants, uppercase, lowercase characters in a string
Source Code:
#Count the no.of vowels, consonants, uppercase, lowercase
# characters in string.
str = input("Enter the string: ")
v_count=0
c_count=0
upper_count=0
lower_count=0
vowel = "aeiouAEIOU"
for alphabet in str:
if vowel.find(alphabet)!=-1:
v_count=v_count +1
elif alphabet == chr(32): #check for space
pass
else:
c_count=c_count+1
if alphabet.isupper():
upper_count += 1
elif alphabet.islower():
lower_count += 1
print("Number of Vowels :",v_count)
print("Number of Consonants :",c_count)
print("Number of upper case letters :",upper_count)
print("Number of lower case letters :",lower_count)
Sample Output:
Enter the string: Hello World
Number of Vowels : 3
Number of Consonants : 7
Number of upper case letters : 2
Number of lower case letters : 8
Conclusion:
The above Python program was executed successfully
Task -33
Write a program in python to create a List and find the minimum
and maximum value.
Aim:
To write a program in python to create a List and find the minimum
and maximum value.
Source Code:
list1 = []
# Input number of elements to put in list
num = int(input("Enter number of elements in list: "))
print("Enter the elements")
for i in range(1, num + 1):
element= int(input())
list1.append(element)
print("The Given list is",list1)
print("Smallest element in the list is:", min(list1))
print("Largest element in the list is:", max(list1))
Conclusion:
The above Python program was executed successfully
Task 34:
Write a program in python to search for an element in a List
using linear search
Aim:
To write a program in python to search for an element in a List using
linear search
Source Code:
mylist = []
# Input number of elements to put in list
num = int(input("Enter number of elements in list: "))
print(“Enter the elements”)
for i in range(num):
value = int(input())
mylist.append(value)
element = int(input("Enter an element to be searched: "))
for i in range(num):
if element == mylist[i]:
print("\nElement found at Index:", i)
break
else:
print("Element not found")
Conclusion:
The above Python program was executed successfully
Task 35:
Write a program in python to create a Tuple and perform basic
built-in functions
Aim:
To write a program in python to create a Tuple and perform basic
built-in functions
Source Code:
t1=(34,56,13,78,23,90)
print("The given tuple is \n",t1)
print("1.min")
print("2.max")
print("3.Sum")
print("4.Count")
print("5.sort")
print("Any other number to exit")
while(True):
ch=int(input("Enter your choice"))
if ch==1:
print(min(t1))
elif ch==2:
print(max(t1))
elif ch==3:
print(sum(t1))
elif ch==4:
a=int(input("Enter the value to be counted"))
print("The value occurs ",t1.count(a)," times")
elif ch==5:
print(sorted(t1))
else:
break
Sample input and output:
The given tuple is
(34, 56, 13, 78, 23, 90)
1.min
2.max
3.Sum
4.Count
5.sort
Any other number to exit
Enter your choice2
90
Enter your choice3
294
Enter your choice7
Task 36:
Aim :
To write a Program in Python to implement the use of built-in
functions in Statistics Module
Source Code:
import statistics as st
list1=[]
num = int(input("Enter number of elements in list: "))
print("Enter the elements")
for i in range(1, num + 1):
element= int(input())
list1.append(element)
print("The Given list is",list1)
print("Mean of the list is ",st.mean(list1))
print("Median of the list is ",st.median(list1))
print("Mode of the list is ", st.mode(list1))
Conclusion:
The above Python program was executed successfully
Task 37:
Aim :
To write a Program in Python to implement the use of built-in
functions in Random Module
Source Code:
import random as rd
print(“Specify lower and upper value to generate random number”)
low=int(input("Enter the lower range"))
up=int(input("Enter the upper range"))
print("Random Number using Randint " , rd.randint(low,up))
print("Random Number using Randrange " , rd.randrange(low,up))
print("Random Number using Random (Any number)",rd.random())
print("Random Number using Random ",low+rd.random()*(up-low))
Conclusion:
The above Python program was executed successfully