0% found this document useful (0 votes)
2 views

Practical_Python

The document is a Computer Science lab manual containing various Python programming exercises aimed at teaching fundamental programming concepts. Each program includes an aim, flowchart, and space for program code and output. Topics covered include number swapping, arithmetic operations, area and perimeter calculations, simple interest, and string manipulations among others.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Practical_Python

The document is a Computer Science lab manual containing various Python programming exercises aimed at teaching fundamental programming concepts. Each program includes an aim, flowchart, and space for program code and output. Topics covered include number swapping, arithmetic operations, area and perimeter calculations, simple interest, and string manipulations among others.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

I PUC – COMPUTER SCIENCE LAB MANUAL

PYTHON-PART A
PROGRAM 1: Write a program to swap two numbers using a third variable.

AIM: To swap two numbers using a third variable.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 1


Program: Output:

Krithika Sivakumar, Department of Computer Science 2


PROGRAM 2: Write a program to enter two integers and perform all
arithmetic operations on them.
AIM: To enter two integers and perform all arithmetic operations on them.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 3


Program:

Output:

Krithika Sivakumar, Department of Computer Science 4


PROGRAM 3: Write a Python program to accept length and width of a
rectangle and compute its perimeter and area.
AIM: To accept length and width of a rectangle and compute its perimeter
and area.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 5


Program:

Output:

Krithika Sivakumar, Department of Computer Science 6


PROGRAM 4 : Write a Python program to calculate the amount payable if
money has been lent on simple interest. Principal or money lent = P, Rate
of interest = R% per annum and Time = T years. Then Simple Interest (SI) =
(P x R x T)/ 100.
Amount payable = Principal + SI.
P, R and T are given as input to the program.
AIM: To calculate the Simple Interest and amount payable
FLOWCHAT:

Krithika Sivakumar, Department of Computer Science 7


Program:

Output:

Krithika Sivakumar, Department of Computer Science 8


PROGRAM 5: Write a Python program to find largest among three
numbers.
AIM: To find the largest among three numbers.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 9


Program:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 10


PROGRAM 6: Write a 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).
AIM: To input a value from the user and display whether the user is
eligible to apply for a driving license or not.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 11


Program:

OUTPUT:1

OUTPUT:2

Krithika Sivakumar, Department of Computer Science 12


PROGRAM 7: Write a program that prints minimum and maximum of
five numbers entered by the user.
AIM: To print the minimum and maximum of five numbers entered by the
user.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 13


Program:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 14


PROGRAM 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

AIM: To find the grade of a student according to the percentage given.


FLOWCHART:

Krithika Sivakumar, Department of Computer Science 15


PROGRAM:

OUTPUT 1:

OUTPUT 2:

Krithika Sivakumar, Department of Computer Science 16


PROGRAM 9: Write a function to print the table of a given number. The
number has to be entered by the user.
AIM: To print the table of a given number. The number has to be entered
by the user.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 17


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 18


PROGRAM 10: Write a program to find the sum of digits of an integer
number, input by the user.
AIM: To find the sum of digits of an integer number, input by the user.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 19


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 20


PROGRAM 11: Write a program to check whether an input number is a
palindrome or not.
AIM: To check whether an input number is a palindrome or not.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 21


PROGRAM:

OUTPUT 1:

OUTPUT 2:

Krithika Sivakumar, Department of Computer Science 22


PROGRAM 12: Write a program to print the following patterns:
12345
1234
123
12
1
(Hint: Use nested for loop statement only)
AIM: To print the patterns
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 23


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 24


PART-B
PROGRAM:
13. Write a program that uses a user defined function that accepts name
and gender (as M for Male, F for Female) and prefixes Mr./Ms. based on the
gender.
AIM: To create a user defined function that accepts name and gender and
apply prefixes based on the gender.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 25


PROGRAM:

Krithika Sivakumar, Department of Computer Science 26


OUTPUT:

Krithika Sivakumar, Department of Computer Science 27


PROGRAM:
14. Write a program that has a user defined function to accept the
coefficients of a quadratic equation in variables and calculates its
discriminant. For example: if the coefficients are stored in the variables a, b,
c then calculate discriminant as b2-4ac. Write the appropriate condition to
check discriminant on positive, zero and negative and output appropriate
result.
AIM: To find the Quadratic equation using user defined function.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 28


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 29


Krithika Sivakumar, Department of Computer Science 30
PROGRAM
15.Write a program that has a user defined function to accept 2 numbers as
parameters, if number 1 is less than number 2 then numbers are swapped
and returned, i.e., number 2 is returned in place of number1 and number 1
is reformed in place of number 2, otherwise the same order is returned.
AIM: To Swap the two values according to the condition given, by using the
user defined function with parameters.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 31


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 32


PROGRAM
16. Write a program to input line(s) of text from the user until enter is
pressed. Count the total number of characters in the text (including white
spaces), total number of alphabets, total number of digits, total number of
special symbols and total number of words in the given text. (Assume that
each word is separated by one space).
AIM:
To input line(s) from the user until enter is pressed and count the total
number of characters, alphabets, digits, special symbols and words.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 33


Krithika Sivakumar, Department of Computer Science 34
PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 35


PROGRAM
17. Write a user defined function to convert a string with more than one
word into title case string where string is passed as parameter. (Title case
means that the first letter of each word is capitalized)
AIM: To convert a string with more than one word into title case string
where string is passed as parameter.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 36


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 37


PROGRAM 18.
Write a function that takes a sentence as an input parameter where each
word in the sentence is separated by a space. The function should replace
each blank with a hyphen and then return the modified sentence.
AIM: To input parameter where each word in the sentence is separated by a
space. The function should replace each blank with a hyphen and then
return the modified sentence.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 38


PROGRAM:

RESULT:

Krithika Sivakumar, Department of Computer Science 39


PROGRAM 19:
Write a program to find the number of times an element occurs in the list.

AIM: To find the number of times an element occurs in the list.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 40


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 41


Program 20:
Write a function that returns the largest element of the list passed as
parameter.
AIM: To write a function that returns the largest element of the list passed
as parameter.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 42


Program:

Output:

Krithika Sivakumar, Department of Computer Science 43


Program 21:
Write a program to read a list of elements. Modify this list so that it does
not contain any duplicate elements, i.e., all elements occurring multiple
times in the list should appear only once.
AIM: To read a list of elements. Modify this list so that it does not contain
any duplicate elements
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 44


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 45


PROGRAM22:

Write a program to read email IDs of n number of students and store


them in a tuple. Create two new tuples, one to store only the
usernames from the email IDs and second to store domain names
from the email IDs. Print all three tuples at the end of the program.
[Hint: You may use the function split().

AIM: To read email IDs of n number of students and store them in a


tuple. Create two new tuples, one to store only the usernames from
the email IDs and second to store domain names from the email IDs.
Print all three tuples.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 46


Program:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 47


Program
23. Write a program to input names of n students and store them in a tuple.
Also, input a name from the user and find if this student is present in the
tuple or not.
AIM: To input names of n students and store them in a tuple. and find if this
student is present in the tuple or not.
FLOWCHART:

Krithika Sivakumar, Department of Computer Science 48


Program:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 49


PROGRAM:
24A. Write a Python program to create a dictionary from a string.
Note: Track the count of the letters from the string. Sample string : ‘2nd pu
course’
Expected output : {‘2’:1, ‘n’:1, ‘d’:1, ‘o’:1, ‘p’:1, ‘u’:2, ’c’:1, ‘s’:1, ‘r’:1, ‘e’:1}

AIM: To create a dictionary from a string.

FLOWCHART:

Krithika Sivakumar, Department of Computer Science 50


PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 51


PROGRAM
24B

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.

AIM: 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.
Flowchart:

Krithika Sivakumar, Department of Computer Science 52


Krithika Sivakumar, Department of Computer Science 53
PROGRAM:

OUTPUT:

Krithika Sivakumar, Department of Computer Science 54

You might also like