1.
PROGRAM USING VARIABLES, CONSTANTS, I/O
STATEMENTS IN PYTHON
AIM:
The aim of the program is to calculate the area of a circle using a
constant value for pi and user input for the radius.
PROCEDURE:
Initialize a constant variable PI with the value 3.14159.
Prompt the user to enter the radius of the circle.
Read the input value and store it in a variable radius.
Calculate the area of the circle using the formula area = PI *
radius * radius.
Display the calculated area of the circle.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 1
2. PROGRAM USING OPERATORS IN PYTHON
AIM:
The aim of the program is to perform basic arithmetic operations
using operators in Python.
PROCEDURE:
Prompt the user to enter two numbers.
Read the input values and store them in variables num1 and
num2.
Perform the following operations:
Addition: result = num1 + num2
Subtraction: result = num1 - num2
Multiplication: result = num1 * num2
Division: result = num1 / num2
Modulo: result = num1 % num2
Exponentiation: result = num1 ** num2
Display the results of each operation.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 2
3. PROGRAM USING CONDITIONAL STATEMENTS
AIM:
The aim of the program is to determine whether a given number
is positive, negative, or zero using conditional statements in Python.
PROCEDURE:
Prompt the user to enter a number.
Read the input value and store it in a variable num.
Use conditional statements to check the value of num:
If num is greater than 0, display "Positive number".
If num is less than 0, display "Negative number".
If num is equal to 0, display "Zero".
End the program.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 3
4. PROGRAM USING LOOPS
AIM:
The aim of the program is to display the numbers from 1 to 10
using a loop in Python.
PROCEDURE:
Initialize a variable num with the value 1.
Use a loop to iterate from num to 10 (inclusive).
Print the value of num.
Increment num by 1.
End the loop.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 4
5. PROGRAM USING JUMP STATEMENTS
AIM:
The aim of the program is to demonstrate the use of jumping
statements (break and continue) in Python.
PROCEDURE:
Use a loop to iterate through the numbers from 1 to 10 (inclusive).
Inside the loop, check if the current number is divisible by 3.
If the number is divisible by 3, use the continue statement to skip
the remaining code in the loop and move to the next iteration.
If the number is not divisible by 3, print the number.
Check if the current number is equal to 7.
If the number is equal to 7, use the break statement to exit the
loop.
End the loop.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 5
6. PROGRAM USING FUNCTIONS
AIM:
The aim of the program is to create a function that adds two
numbers in Python.
PROCEDURE:
Define a function named add_numbers that takes two parameters
num1 and num2.
Inside the add_numbers function, add num1 and num2 and store
the result in a variable sum.
Return the value of sum.
Prompt the user to enter two numbers.
Read the input values and store them in variables n1 and n2.
Call the add_numbers function, passing n1 and n2 as arguments,
and store the result in a variable result.
Display the sum of the two numbers.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 6
7. PROGRAM USING RECURSION
AIM:
The aim of the program is to create a function that calculates the
factorial of a given number in Python.
PROCEDURE:
Define a function named factorial that takes a single parameter
num.
Inside the factorial function, initialize a variable result with the
value 1.
Use a for loop to iterate from 1 to num (inclusive).
Multiply result by the current value of the loop variable.
Return the value of result.
Prompt the user to enter a number.
Read the input value and store it in a variable n.
Call the factorial function, passing n as an argument, and store the
result in a variable fact.
Display the calculated factorial value.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 7
8. PROGRAM USING ARRAYS
AIM:
The aim of the program is to demonstrate the use of arrays in
Python by storing and manipulating a list of numbers.
PROCEDURE:
Create an array/list to store numbers.
Prompt the user to enter the size of the array.
Read the input value and store it in a variable size.
Use a loop to iterate size number of times.
Inside the loop, prompt the user to enter a number and append it
to the array.
Calculate the sum and average of the numbers in the array.
Initialize variables sum and average with the value 0.
Use a loop to iterate through each element of the array.
Add each element to the sum variable.
Divide the sum by the size to calculate the average.
Display the array, sum, and average of the numbers.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 8
9. PROGRAM USING STRINGS
AIM:
The aim of the program is to demonstrate various operations and
manipulations on strings in Python.
PROCEDURE:
Prompt the user to enter a sentence.
Read the input value and store it in a variable sentence.
Calculate the length of the sentence using the len() function and
store it in a variable length.
Split the sentence into words using the split() method and store
the resulting list of words in a variable words.
Count the number of words in the sentence by calculating the
length of the words list.
Replace a specific word in the sentence with a new word.
Prompt the user to enter the word to be replaced and the new
word.
Use the replace() method to replace the word in the sentence and
store the modified sentence in a variable modified_sentence.
Display the length of the sentence, the number of words, and the
modified sentence.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 9
10. PROGRAM USING MODULES
AIM:
The aim of the program is to demonstrate the usage of modules
in Python by importing and utilizing functions from a separate module.
PROCEDURE:
Import the required module that contains the desired functions.
Prompt the user to enter two numbers.
Read the input values and store them in variables num1 and
num2.
Call the imported function(s) from the module to perform desired
operations on the input numbers.
Display the output/result of the function(s).
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 10
11. PROGRAM USING LISTS
AIM:
The aim of the program is to demonstrate the usage of lists in
Python by performing various operations on a list of numbers.
PROCEDURE:
Create an empty list to store numbers.
Prompt the user to enter the size of the list.
Read the input value and store it in a variable size.
Use a loop to iterate size number of times.
Inside the loop, prompt the user to enter a number and append it
to the list.
Calculate the sum and average of the numbers in the list.
Initialize variables sum and average with the value 0.
Use a loop to iterate through each element of the list.
Add each element to the sum variable.
Divide the sum by the size to calculate the average.
Find the maximum and minimum values in the list using the
max() and min() functions.
Display the list, sum, average, maximum, and minimum values.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 11
12. PROGRAM USING TUPLES
AIM:
The aim of the program is to demonstrate the usage of tuples in
Python by performing operations and accessing elements of a tuple.
PROCEDURE:
Create a tuple to store a collection of elements.
Prompt the user to enter values for the tuple.
Read the input values and store them in variables.
Perform operations on the tuple:
Calculate the length of the tuple using the len() function.
Access individual elements of the tuple using indexing.
Slice the tuple to extract a subset of elements.
Concatenate two tuples using the + operator.
Display the length of the tuple, individual elements, sliced
elements, and the concatenated tuple.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 12
13. PROGRAM USING DICTIONARIES
AIM:
The aim of the program is to demonstrate a simple usage of
dictionaries in Python by storing and accessing information about a
person.
PROCEDURE:
Create an empty dictionary to store information.
Prompt the user to enter the name, age, and city of a person.
Read the input values and store them in variables.
Add the information to the dictionary using appropriate keys.
Access the information from the dictionary using the keys.
Display the stored information.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 13
14. PROGRAM FOR FILE HANDLING
AIM:
The aim of the program is to demonstrate file handling in Python
by reading and writing data to a file.
PROCEDURE:
Prompt the user to enter a file name.
Open the file in write mode and create a file object.
Prompt the user to enter data to be written to the file.
Write the data to the file using the file object.
Close the file.
Open the file in read mode and create a new file object.
Read the contents of the file using the file object.
Display the contents of the file.
Close the file.
SSASC Dept. Of Computer Science bbalaji@sankaracollege.edu.in I B.C.A Girls
Page | 14