0% found this document useful (0 votes)
3 views26 pages

Practical File

This document is a practical file submitted by Kavin Arun Prasad for a Computer Science course, containing various programming exercises. It includes programs for arithmetic operations, simple interest, conversions, and checks for properties of numbers, among others. Each program is accompanied by its aim, coding, output, and verification results.

Uploaded by

Kavin Arun
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views26 pages

Practical File

This document is a practical file submitted by Kavin Arun Prasad for a Computer Science course, containing various programming exercises. It includes programs for arithmetic operations, simple interest, conversions, and checks for properties of numbers, among others. Each program is accompanied by its aim, coding, output, and verification results.

Uploaded by

Kavin Arun
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Kovaipudur, Coimbatore – 641042

Affiliation No: 1930510

PRACTICAL FILE

Submitted
by:

Kavin Arun
Prasad
[XI-D]

Under the
Guidance of:

Miss Akhila
PGT
(CSc)
CERTIFICATE

Certified that this is the bonafide record


of the practical work in Computer
Science done by Kavin Arun Prasad (XI-
D) and is submitted for the Practical
Examination at CS Academy, Coimbatore
on _____________________.

…………………………………
Signature of the Teacher
INDEX
[Link] PROGRAMS PAGE NO SIGNATUR
E

1 Arithmetic operations

2 Simple interest

3 Farenheit to Celcius

4 Greatest of three numbers

5 Grades of the student

6 Factorial of a number

7 Fibonacci series

8 Sum of the digits of a number

9 Reverse of a number

10 Armstrong number

11 Perfect number

12 Prime number

13 Palindrome

14 Number of lower, upper and digits in a given


string.

15 String functions

16 Pattern programs

17 Linear Search

18 Largest/smallest number in a tuple

19 List manipulation

20 Dictionary
[Link] ARITHMETIC OPERATIONS
Question:
Write a program to write a program to perform all arithmetic operations.

AIM:
To write a program to perform all arithmetic operations.

CODING:
ch = 'y'
while ch == 'y':
print('''Select a the function you want to perform:
a. Addition
b. Subtraction
c. Multiplication
d. Division''')
n = input('Enter an option: ')
a = int(input('Enter number 1: '))
b = int(input('Enter number 2: '))
if n == 'a':
print(a+b)
elif n == 'b':
print(a-b)
elif n == 'c':
print(a*b)
elif n == 'd':
print(a/b)
else:
print('Enter a valid option')
ch = input('Continue?(y/n): ')

OUTPUT:
RESULT:
The above code has been verified and executed successfully.

[Link] SIMPLE INTEREST


Question:
Write a program to find simple interest.

AIM:

To find simple interest:

CODING:
a = int(input('Enter Amount in Account: '))
b = int(input('Enter percentage of interest: '))
c = int(input('Enter no. of years: '))
d = (a*b*c)/100
print('Simple interest on', a, 'rupees after', c, 'years for', b,'percent per annum
is', d,'rupees')

OUTPUT:

RESULT:
The above code has been verified and executed successfully.

[Link] FARENHEIT to CELCIUS


Question:
Write a program to convert fahrenheit to celcius.

AIM:

To write a program to convert Fahrenheit to Celsius

CODING:
a = int(input('Enter temperature in farenheit: '))
print(a, 'Degrees Fahrenheit in Celsius is', (a-32)*(5/9),'Degrees')

OUTPUT:

RESULT:
The above code has been verified and executed successfully.

[Link] GREATEST OF THREE NUMBERS

Question:
Write a program to find the greatest of three numbers.

AIM:
To write a program to find the greatest of three numbers.

CODING:
a = int(input('Enter the first number: '))
b = int(input('Enter the second number: '))
c = int(input('Enter the third number: '))
if a>b and a>c:
print(a, 'is the greatest number')
elif b>a and b>c:
print(b, 'is the greatest number')
else:
print(c, 'is the greatest number')

OUTPUT:

RESULT:
The above code has been verified and executed successfully.

[Link] GRADES OF THE STUDENT

Question:
Write a program to display the grades of the student based on average marks
obtained.
AIM:
To display the grades of the student based on the average obtained.

90 – 100 = A
80 – 89 = B
70 – 79 = C
60 – 69 = D
<60 = E

CODING:
a = int(input('Enter the average grade of the student: '))
if a<=100 and a>=90:
print('This student has been graded A')
elif a<=89 and a>=80:
print('This student has been graded B')
elif a<=79 and a>=70:
print('This student has been graded C')
elif a<=69 and a>=60:
print('This student has been graded D')
else:
print('This student has been graded E')

OUTPUT:

RESULT:
The above code has been verified and executed successfully.

[Link] FACTORIAL OF A NUMBER

Question:
Write a program to find the factorial of a number.

AIM:

To find the factorial of a number.


CODING:
print('Factorial Calculator')
n = int(input('Enter a number:'))
x=1
for i in range(1, n+1):
x = x*i
print(x)

OUTPUT:

RESULT:
The above code has been verified and executed successfully.

[Link] FIBONACCI SERIES

Question:
Write a program to print the fibonacci series.

AIM:

To print fibonacci series.


CODING:
n = int(input('Enter no. of terms:'))
a=0
b=1
for i in range(n):
c = a+b
print(c, end=' ')
a=b
b=c

OUTPUT:

RESULT:
The above code has been verified and executed successfully.

[Link] SUM OF DIGITS OF A NUMBER

Question:
Write a program to find the sum of digits of a number.

AIM:

To find sum of digits of a number.

CODING:
n = input('Enter a number: ')
a=0
for i in n:
a = a + int(i)
print('The sum is: 'a)

OUTPUT:

RESULT:
The above code has been verified and executed successfully.

[Link] REVERSE OF A NUMBER

Question:
Write a program to find the reverse of a number.

AIM:

To find reverse of a number

CODING:
n = input('Enter a number:')
a = ''
for i in range(-1, -(len(n)+1), -1):
a = a + n[i]
print('Reversed number is',a)

OUTPUT:

[Link] ARMSTRONG NUMBER

Question:
Write a program to check if the given number is an armstrong or not.

AIM:

To check if the number is an armstrong or not

CODING:
num = int(input('Enter a 3 digit number:'))
c = num
b=0
for i in range(1,4):
z = c%10
b += (z**3)
c //= 10
if b == num:
print('This is an Armstrong number')
else:
print('This is not an armstrong number')

OUTPUT:

[Link] PERFECT NUMBER

Question:
Write a program to check if a number is perfect or not.

AIM:

To check if number is a perfect number or not

CODING:
n = int(input('Enter a number: '))
a=0
for i in range(1,n):
if(n%i == 0):
a = a+i
if a == n:
print('Yes,',n,'is a perfect number')
else:
print('No,',n,'is not a perfect number')
OUTPUT:

[Link] PRIME NUMBER

Question:
Write a program to generate prime numbers between any given range.

AIM:

To generate prime numbers between any given range

CODING:
a = int(input('Enter lower limit of range: '))
b = int(input('Enter upper limit of range: '))
for i in range(a,b+1):
for j in range(2,i):
if i%j == 0:
break
else:
print(i)
break
OUTPUT:

[Link] PALINDROME

Question:
Write a program to check if a given number is pallindrome or not.

AIM:

To check if the given number is a pallindrome or not

CODING:
n = int(input('Enter the no:'))
a=n
b=0
while a > 0:
x = a%10
b = b*10 + x
a = a//10
if b == n:
print('This is a pallindrome number:')
else:
print('This is not a pallindrome number')
OUTPUT:

RESULT:
The above code has been verified and executed successfully.

[Link] NUMBER OF LOWER, UPPER AND


DIGITS IN A STRING

Question:
Write a program to find the number of lower, upper and digits in a string.

AIM:

To find the number of lower, upper and digits in a string

CODING:
n = input('Enter a string: ')
for i in n:
if [Link]():
print(i, 'is a digit')
elif [Link]():
print(i, 'is in uppercase')
elif [Link]():
print(i, 'is in lowercase')
else:
print(i,'is a special character')

OUTPUT:
RESULT:
The above code has been verified and executed successfully.
[Link] STRING FUNCTIONS

Question:
Write a program to read a string and use all methods related to it, including
partition, split, join, etc.

AIM:

To read a string and use all the methods related to a string. It should include
partition, split,
join etc.,

CODING:
a = input('Enter a string: ')
b = input('Enter substring: ')
print('len() ---->:',len(a))
print('capitalize() ---->:',[Link]())
print('count() ---->:',[Link](b))
print('find() ---->:',[Link](b))
print('index() ---->:',[Link](b))
print('isalnum() ---->:',[Link]())
print('isalpha() ---->:',[Link]())
print('isdigit() ---->:',[Link]())
print('islower() ---->:',[Link]())
print('isupper() ---->:',[Link]())
print('isspace() ---->:',[Link]())
print('lower() ---->:',[Link]())
print('upper() ---->:',[Link]())
print('lstrip() ---->:',[Link]())
print('rstrip() ---->:',[Link]())
print('strip() ---->:',[Link]())
print('startswith() ---->:',[Link](b))
print('endswith() ---->:',[Link](b))
print('title() ---->:',[Link]())
print('istitle() ---->:',[Link]())
print('replace() ---->:',[Link](a[2:5],b))
print('join() ---->:',[Link](b))
print('split() ---->:',[Link](b))
print('partition() ---->:',[Link](b))

OUTPUT:
RESULT:
The above code has been verified and executed successfully.

[Link]: 16 PATTERN PROGRAMS

Question:
Write a program to print three of the following patterns

AIM:

To print the pattern:


A
AB
ABC
ABCD

CODING:
a = int(input('Enter no. of iterations: '))
for i in range(1,a+1):
for j in range(65,65+i):
print(chr(j), end=' ')
print()

OUTPUT:
RESULT:
The above code has been verified and executed successfully.

AIM:

To print the pattern:


1
12
123
1234

CODING:
a = int(input('Enter no. of iterations: '))
for i in range(1,a+1):
for j in range(1,i+1):
print(j, end=' ')
print()

OUTPUT:

RESULT:
The above code has been verified and executed successfully.

AIM:
To print pattern:
*
**
***

CODING:
a = int(input('Enter no. of iterations: '))
for i in range(1,a+1):
for j in range(1,i+1):
print('*', end=' ')
print()

OUTPUT:

RESULT:
The above code has been verified and executed successfully.
[Link] LINEAR SEARCH

Question:
Write a program to read a list of numbers and check if number lies in it.

AIM:

To read a list of numbers and check if no. lies in list

CODING:
a = []
ch = 'y'
while ch == 'y':
b = int(input('Enter a number: '))
[Link](b)
ch = input('Continue?(y/n): ')
c = int(input('Enter no. to search: '))
if c in a:
print(c, 'lies in',[Link](c),'position')
else:
print(c,'does not lie in the list')
OUTPUT:
RESULT:
The above code has been verified and executed successfully.
[Link] LARGETS/SMALLEST IN A TUPLE

Question:
Write a program to find the maximum value in a tuple.

AIM:

To find maximum value in a tuple

CODING:
a = tuple(eval(input('Enter a tuple of numbers: ')))
print(max(a), 'is the largest number')

OUTPUT:

RESULT:
The above code has been verified and executed successfully.
[Link] LIST MANIPULATION

Question:
Write a program to input a list of numbers and swap elements at the even
location with the elements at the odd locations.

AIM:

To write a program to input a list of numbers and swap elements at the even
location with the elements at the odd location.

CODING:
n = int(input('Enter number of elements of list: '))
a = []
for i in range(n):
b = input('Enter element: ')
[Link](b)
print(a)
for i in range(0,n-1,2):
b = a[i]
a[i] = a[i+1]
a[i+1] = b
print(a)

OUTPUT:
RESULT:
The above code has been verified and executed successfully.

You might also like