0% found this document useful (0 votes)
12 views6 pages

Python Programs Aim & Algorithm

The document outlines 12 Python programs, each with distinct aims and algorithms. These programs cover various topics including operators, branching and looping constructs, string operations, tuple operations, dictionary and set operations, NumPy array manipulations, package creation, and handling data with Pandas. Each program includes a step-by-step algorithm to implement the specified functionalities.

Uploaded by

tharunspidey130
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)
12 views6 pages

Python Programs Aim & Algorithm

The document outlines 12 Python programs, each with distinct aims and algorithms. These programs cover various topics including operators, branching and looping constructs, string operations, tuple operations, dictionary and set operations, NumPy array manipulations, package creation, and handling data with Pandas. Each program includes a step-by-step algorithm to implement the specified functionalities.

Uploaded by

tharunspidey130
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

Program 1: Write a Python program to implement the different operators.

Aim:

To write a Python program that demonstrates the use of different types of operators, including
arithmetic, comparison, and logical operators.

Algorithm:

1. Start the program.

2. Initialize two variables a and b with integer values.

3. Perform Arithmetic Operations:

Apply basic arithmetic operations (addition, subtraction, multiplication, etc.) on a and b and
display the results.

4. Perform Comparison Operations:

Compare a and b using various comparison operators (e.g., equality, greater than, less than) and
print whether each condition is True or False.

5. Perform Logical Operations:

Use logical operators to check combined conditions involving a and b (e.g., and, or, not) and print
the results.

6. End the program.

Program 2: Write a python program to implement branching and looping constructs.

Aim:

To write a Python program demonstrating branching and looping constructs.

Algorithm:

1. Accept a number as input from the user.

2. Use branching to check if the number is positive, negative, or zero, and print the result.

3. Use a for loop to print numbers from 1 to 5.

4. Use a while loop to print numbers from 1 to 5.

5. Demonstrate the break statement by stopping a loop when the number is 3.

6. Demonstrate the continue statement by skipping the number 3 in a loop.

7. End the program.


Program 3: Python program to implement string operations and functions

Aim:

To write a Python program that demonstrates various string operations and functions.

Algorithm:

1. Create a string variable with sample text.


2. Print the length of the string.
3. Convert the string to uppercase and lowercase and print the results.
4. Remove leading and trailing whitespace and print the stripped string.
5. Split the string into a list of words and print the list.
6. Join the list of words back into a single string and print it.
7. Replace a substring within the string and print the modified string.
8. Find the index of a specific substring and print the index.
9. Check if a specific substring is present in the string and print the result.
10. End the program.

Program 4: Create a Python program to implement various operations on tuple

Aim:

To write a Python program that demonstrates various operations and functions on tuples.

Algorithm:

1. Create a tuple with integer elements and another mixed-type tuple.

2. Print the length of the tuple.

3. Access and print an element by its index.

4. Slice the tuple and print the result.

5. Concatenate the tuple with another tuple and print it.

6. Repeat the tuple a specified number of times and print the result.

7. Check if an element exists in the tuple and print the result.

8. Find the index of a specific element and print it.

9. Count the number of occurrences of a specific element in the tuple and print the result.

10. End the program.


Program 5: Program to implement Dictionary and sets

Aim:

To write a Python program that demonstrates various operations and functions on dictionaries and sets.

Algorithm:

1. Create and initialize a dictionary and print it.

2. Access and print specific values using dictionary keys.

3. Add or update entries in the dictionary and display the changes.

4. Remove an entry from the dictionary and print the updated result.

5. Iterate through the dictionary and print its keys and values.

6. Create and initialize two sets; perform and display set operations like add, remove, union,
intersection, and difference.

7. Check membership of elements in a set and print the results.

8. Iterate through a set and print each element.

9. End the program.

Program 6: Program for operations on NumPy arrays.

Aim:

To write a Python program to demonstrate various operations on NumPy arrays, including arithmetic
operations, dot product, mean calculation, and array reshaping.

Algorithm:

1. Import the NumPy library.

2. Create two arrays array1 and array2 using [Link]().

3. Perform basic arithmetic operations – Add, Subtract, Multiply and Divide the arrays 1 and 2

4. Print the results of these arithmetic operations.

5. Calculate the dot product of array1 and array2 using [Link]().

6. Find and print the mean of array1 and array2 using [Link]().

7. Reshape array1 to a 1x5 array using reshape() and print the result.

8. Display all outputs to demonstrate the operations.


Program 7: Program to test math functions using NumPy

Aim:

To write a Python program to demonstrate various mathematical functions using NumPy, including
trigonometric, exponential, logarithmic, and square root functions.

Algorithm:

1. Import the NumPy library.

2. Create an array of angles in degrees.

3. Convert the array of angles from degrees to radians using [Link]().

4. Calculate and print the sine, cosine, and tangent values using [Link](), [Link](), and [Link]().

5. Test exponential functions by calculating e^x using [Link]() and print the results.

6. Create an array and calculate the natural logarithm using [Link](), then print the results.

7. Create an array of numbers and calculate their square root using [Link](), then print the results.

8. Display all outputs to show the results of these mathematical operations.

9. End the program.

Program 8: Program to perform stacking and splitting operations using NumPy.

Aim:

To write a Python program to perform stacking and splitting operations on arrays using NumPy.

Algorithm:

1. Import the NumPy library.

2. Create two sample arrays.

3. Perform stacking operations vertically using [Link](), horizontally using [Link](), column-
wise using np.column_stack()

4. Print the results of the stacking operations.

5. Perform splitting operations: two equal parts using [Link]() and individual rows using
[Link]().

6. Print the results of the splitting operations.

7. Display the final output to show the results of all operations.

8. End the program.


Program 9: Program to implement Packages

Aim:

To write a Python program that demonstrates the creation and usage of packages in Python.

Algorithm:

1. Create a main package folder named package.

2. Create a subfolder inside package named samplepkg.

3. Create __init__.py file in the samplepkg folder to make it a Python package.

4. Create a Python file [Link] in the samplepkg folder and define a function greetmsg() that prints
a welcome message and it includes simple arithmetic operations for demonstration..

5. Create a main Python file [Link] in the package folder.

6. Import the Msg module from the samplepkg package using from samplepkg import Msg.

7. Call the greetmsg() function in [Link] using [Link]().

8. End the program.

Program 10: Read a set of array values and create series and data frame using Pandas.

Aim:

To write a Python program that reads a set of array values and creates a Pandas Series and DataFrame
from those values.

Algorithm:

1. Import the Pandas library using import pandas as pd.

2. Read a set of array values and store them in a list.

3. Create a Pandas Series from the array values using [Link]().

4. Print the Pandas Series.

5. Create a DataFrame from the Series using [Link]() and specify a column name.

6. Print the DataFrame to display the result.

7. End the program.


Program 11: Program to find the missing values using Pandas.

Aim:

To write a Python program that identifies and handles missing values in a Pandas DataFrame.

Algorithm:

1. Import the Pandas library using import pandas as pd.

2. Create a sample DataFrame with some missing values.

3. Display the original DataFrame.

4. Detect missing values using isnull(), which returns True for missing data.

5. Count the number of missing values in each column using isnull().sum().

6. Optionally, drop rows with missing values using dropna() and display the result.

7. Optionally, fill missing values using fillna() and display the updated DataFrame.

8. End the program.

Program 12: Program to apply reading operation in CSV file.

Aim:

To write a Python program that reads and displays a CSV file using Pandas and extracts basic information
and statistics from it.

Algorithm:

1. Import the Pandas library using import pandas as pd.

2. Specify the file path for the CSV file.

3. Read the CSV file using pd.read_csv() and store it in a DataFrame (df).

4. Print the contents of the DataFrame to view the data.

5. Display basic information about the DataFrame using [Link]().

6. Display statistical summary of the DataFrame using [Link]().

7. End the program.

You might also like