Gr11 Record Programs
Gr11 Record Programs
PROGRAM NO: 1
AIM:
Program to print the given message and display it.
SOURCE CODE:
welcome_message=input("Enter welcome message : ")
print("Hello, ",welcome_message)
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter welcome message : Welcome to Python
Hello, Welcome to Python
DATE : 22/7/23 FIND THE SMALLEST / LARGEST OF TWO NUMBERS
PROGRAM NO: 2
AIM:
Program to find the smallest / largest of two numbers
SOURCE CODE:
#input first number
if (num1>num2):
else:
print ("The Larger number is", num2)
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter First Number77
Enter Second Number63
The Larger number is 77
DATE : 22/7/23 FIND THE SMALLEST / LARGEST OF THREE NUMBERS
PROGRAM NO: 3
AIM:
Program to find the smallest / largest of three numbers
SOURCE CODE:
#input first,Second and third number
else:
print ("The Largest number is", num3)
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter First Number :11
Enter Second Number :1
Enter Third Number :13
The Largest number is 13
DATE : 05/08/23 DISPLAY THE GIVEN PATTERN 1
PROGRAM NO: 4
AIM:
Program to display the given pattern
*
* *
* * *
* * * *
* * * * *
SOURCE CODE:
for i in range(1,6):
for j in range(i):
print(" * ", end = "")
print( )
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
*
* *
* * *
* * * *
* * * * *
DATE : 05/08/23 DISPLAY THE GIVEN PATTERN 2
PROGRAM NO: 5
AIM:
Program to display the given pattern
12345
1234
123
12
1
SOURCE CODE:
n=int(input("Enter a number "))
for i in range(n,0,-1):
for j in range(1, i+1):
print(j, end = " ")
print()
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter a number 5
12345
1234
123
12
1
DATE : 05/08/23 DISPLAY THE GIVEN PATTERN 3
PROGRAM NO: 6
AIM:
Program to display the given pattern
A
AB
ABC
ABCD
ABCDE
SOURCE CODE:
for i in range(1,6):
for j in range(65,65+i):
a=chr(j)
print(a,end=" ")
print()
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
A
AB
ABC
ABCD
ABCDE
DATE : 12/08/23 EVALUATE THE GIVEN SERIES : 1 + X+ X2 + ….. + Xn
PROGRAM NO: 7
AIM:
Program to input the value of x and n and print the sum of the following series
1 + X+ X2 + ….. + Xn .
SOURCE CODE:
x=int(input("Enter the value of x:"))
n=int(input("Enter the total number of terms of the series"))
sum=0
for i in range(n):
sum+=(x**i)
print("The sum of the series is ",sum)
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter the value of x:3
Enter the total number of terms of the series4
The sum of the series is 40
DATE : 12/08/23 EVALUATE THE GIVEN SERIES : 1 - X+ X2 – X3….. + Xn
PROGRAM NO: 8
AIM:
Program to input the value of x and n and print the sum of the following series
1 - X+ X2 – X3….. + Xn .
SOURCE CODE:
x=int(input("Enter the value of x:"))
n=int(input("Enter the total number of terms of the series"))
sum=1
for i in range(1,n):
if i%2==0:
sum+=(x**i)
else:
sum-=(x**i)
print("The sum of the series is ",sum)
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter the value of x:3
Enter the total number of terms of the series4
The sum of the series is -20
DATE : 12/08/23 EVALUATE THE GIVEN SERIES : X + X2/2 - X3/3 ….. + Xn/n
PROGRAM NO: 9
AIM:
Program to input the value of x and n and print the sum of the following series
X + X2/2 - X3/3 + ….. + Xn/n
SOURCE CODE:
x=int(input("Enter a number: "))
n=int(input("Enter the power: "))
s=x
sign=+1
for a in range(2,n+1):
term=((x**a)*sign)/a
s+=term
sign*=-1
print("Sum of first",n,"terms is",s)
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter a number: 2
Enter the power: 6
Sum of first 6 terms is 9.6
DATE : 12/08/23 EVALUATE THE GIVEN SERIES : X + X2/2! - X3/3! + ….. + Xn/n!
PROGRAM NO: 10
AIM:
Program to input the value of x and n and print the sum of the following series
X + X2/2! - X3/3! + ….. + Xn/n!
SOURCE CODE:
x=int(input("Enter a number: "))
n=int(input("Enter the power: "))
s=x
sign=+1
for a in range(2,n+1):
f=1
for i in range(1,a+1):
f*=i
term=((x**a)*sign)/f
s+=term
sign*=-1
print("Sum of first",n,"terms is",s)
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter a number: 2
Enter the power: 6
Sum of first 6 terms is 3.155555555555556
DATE : 26/08/23 PERFECT NUMBER
PROGRAM NO: 11
AIM:
Program to determine whether a given number is a perfect number or not.
SOURCE CODE:
# Perfect number, a positive integer that is equal to the sum
of its proper divisors.
number=int(input("Enter the number"))
sum1 = 0
for i in range(1, number):
if(number % i == 0):
sum1 = sum1 + i
if (sum1 == number):
print(number, " is a Perfect number")
else:
print(number, " is not a Perfect number")
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter the number6
6 is a Perfect number
DATE : 26/08/23 ARMSTRONG NUMBER
PROGRAM NO: 12
AIM:
Program to determine whether a given number is an Armstrong number or not.
SOURCE CODE:
# Armstrong number is equal to sum of cubes of each digit
num1=int(input("Enter a number :"))
sum = 0
temp = num1
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num1 == sum:
print(num1," is an Armstrong number")
else:
print(num1," is not an Armstrong number")
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter a number :371
371 is an Armstrong number
DATE : 26/08/23 PALINDROME NUMBER
PROGRAM NO: 13
AIM:
Program to determine whether a given number is a Palindrome number or not.
SOURCE CODE:
# Palindrome- the number equals to reverse of the number
number=int(input("Enter any number:"))
num=number
num1= number
rev=0
while num>0:
digit=num%10
rev=rev*10+digit
num=int(num/10)
if number==rev:
print(number ,'is a Palindrome')
else:
print(number , 'Not a Palindrome')
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter any number:123321
123321 is a Palindrome
DATE : 26/08/23 PRIME / COMPOSITE NUMBER
PROGRAM NO: 14
AIM:
Program to check if the given number is a prime or composite number
SOURCE CODE:
num = int(input("Enter any number : "))
if num > 1:
for i in range(2, num):
if (num % i) == 0:
print(num, "is NOT a PRIME number, it is a
COMPOSITE number")
break
else:
print(num, "is a PRIME number")
elif num == 0 or 1:
print(num, "is a neither Prime NOR Composite number")
else:
pass
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter any number : 37
37 is a PRIME number
DATE : 02/09/23 FIBONACCI SERIES
PROGRAM NO: 15
AIM:
Program to display the terms of a Fibonacci series.
SOURCE CODE:
# Program to display the Fibonacci sequence up to n-th term
nterms = int(input("How many terms ? "))
# first two terms
n1, n2 = 0, 1
count = 0
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1,end=" , ")
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
SOURCE CODE:
# GCD PROGRAM
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("Greatest Common Divisor (GCD) is ", gcd)
# LCM PROGRAM
if num1 > num2:
greater = num1
else:
greater = num2
while(True):
if((greater % num1 == 0) and (greater % num2 == 0)):
lcm = greater
break
greater += 1
print("The Least Common Multiple (LCM) is ", lcm)
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter 1st number: 2
Enter 2nd number: 4
Greatest Common Divisor (GCD) is 2
The Least Common Multiple (LCM) is 4
DATE : 02/09/23 COUNT THE NUMBER OF VOWELS,CONSONANTS,
UPPERCASE, LOWERCASE CHARATCTERS IN STRING
PROGRAM NO: 17
AIM:
Program to count and display the number of vowels, consonants, uppercase
and lowercase characters in a string.
SOURCE CODE:
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Type the string: Hello World
Number of Vowels in Hello World is : 3
Number of Consonants in Hello World is : 7
Number of UPPER Case in Hello World ' is : 2
Number of lower case in Hello World ' is : 8
DATE : 02/09/23 PALINDROME STRING
PROGRAM NO: 18
AIM:
Program to input a string and determine whether it is a palindrome or not and
convert the case of characters in the string.
SOURCE CODE:
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter a string:malayalam
malayalam is a Palindrome string
DATE : 26/09/23 LARGEST / SMALLEST NUMBER IN A LIST / TUPLE
PROGRAM NO: 19
AIM:
Program to find the largest / smallest number in a list.
SOURCE CODE:
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter the no. of elements in the list:6
Enter the element:3
Enter the element:1
Enter the element:7
Enter the element:0
Enter the element:9
Enter the element:2
Smallest element in the list is 0
Largest element in the list is 9
Smallest element in the tuple is 0
Largest element in the tuple is 9
DATE : 14/10/23 SWAP THE ELEMENTS IN A LIST
PROGRAM NO: 20
AIM:
Program to input a list of numbers and swap the elements at the even location
with the elements at the odd location.
SOURCE CODE:
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Total list items to enter =4
Enter the element 10
Enter the element 20
Enter the element 30
Enter the element 40
Original List : [10, 20, 30, 40]
The elements at odd location: [10, 30]
The elements at even location: [20, 40]
List after swapping : [20, 10, 40, 30]
DATE : 28/10/23 FREQUENCY OF ELEMENTS IN A LIST
PROGRAM NO: 21
AIM:
Program to find the frequency of all the elements in the list.
SOURCE CODE:
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Element Frequency
3 2
21 2
5 1
6 2
8 1
DATE : 28/10/23 SEARCH AN ITEM IN A TUPLE
PROGRAM NO: 22
AIM:
Program to search an item in a tuple.
SOURCE CODE:
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter the number of elements in a tuple5
Enter the element10
Enter the element20
Enter the element30
Enter the element40
Enter the element50
Enter the element you want to search20
The element 20 is found at position 1
DATE : 18/11/23 CREATE A DICTIONARY WITH STUDENT DETAILS
PROGRAM NO: 23
AIM:
Program to create a dictionary with the roll number, name and marks of n
students in a class and display the names of students who have marks above
75.
SOURCE CODE:
RESULT:
The above code has been compiled and executed successfully.
OUTPUT:
Enter number of students: 3
Enter Details of student No. 1
Roll No: 01
Student Name: Riya
Marks: 78
Enter Details of student No. 2
Roll No: 02
Student Name: Rishab
Marks: 70
Enter Details of student No. 3
Roll No: 03
Student Name: Seena
Marks: 46
{1: ['Riya', 78], 2: ['Rishab', 70], 3: ['Seena', 46]}
Student name who got more than 75 marks Riya
DATE : 18/11/23 DICTIONARY TO STORE COUNTRY NAME, CAPITAL AND
CURRENCY, DISPLAY THEM AND SEARCH FOT THE DETAIL
PROGRAM NO: 24
AIM:
Program to create a dictionary to store country name, capital and currency and
display them in tabular form. Then search for a country detail and display
them.
SOURCE CODE:
d=dict()
i=1
n=int(input("Enter number of entries"))
while i <=n:
c=input("Enter country:")
cap=input("Enter Capital")
curr=input("Enter currency of the country")
d[c]=(cap,curr)
i=i+1
#tabular form
l=d.keys()
print("\nCountry\t\t","Capital\t\t","Currency")
for i in l:
z=d[i]
print("\n",i,"\t\t",end="")
for j in z:
print(j,"\t\t",end="\t\t")
#Search for the detail
x=input("Enter the country to search")
for i in l:
if i==x:
print("\nCountry\t\t","Capital\t\t","Currency")
z=d[i]
print("\n",i,"\t\t",end="")
for j in z:
print(j,"\t\t",end="\t\t")
break
else:
print("The country name not found in the dictionary")
RESULT:
The above code has been compiled and executed successfully.
OUTPUT: