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

PYTHON PROGRAMMING - Procedure1

The document contains procedures for several Python programs involving various data structures and algorithms: 1) List, tuple, and dictionary operations - including adding/removing/displaying list elements, sorting tuples, and accessing/modifying dictionaries. 2) Mathematical and logical programs - including finding the largest number, checking for prime numbers, determining if a year is a leap year, checking for palindromes, and adding matrices. 3) Validation of passwords using regular expressions. 4) Calendar functions - displaying calendars and months using the calendar module. 5) A simple calculation GUI using Tkinter.

Uploaded by

V J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

PYTHON PROGRAMMING - Procedure1

The document contains procedures for several Python programs involving various data structures and algorithms: 1) List, tuple, and dictionary operations - including adding/removing/displaying list elements, sorting tuples, and accessing/modifying dictionaries. 2) Mathematical and logical programs - including finding the largest number, checking for prime numbers, determining if a year is a leap year, checking for palindromes, and adding matrices. 3) Validation of passwords using regular expressions. 4) Calendar functions - displaying calendars and months using the calendar module. 5) A simple calculation GUI using Tkinter.

Uploaded by

V J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ex-1: a)LIST Operations

Aim: The program appends, deletes and displays elements of a list using class.
Procedure:
A class called check is created and the __init__() method is used to initialize values of
that class.
Methods for adding, removing and displaying elements of the list have been defined.
The menu is printed and the choice is taken from the user.
An object for the class is created.
Using the object, the respective method is called according to the choice taken from the
user.
The final list is printed.

Ex-1: b1)TUPLE Operations


Aim: Given a tuple,sort the list of tuples in increasing order by any key in tuple.
Procedure:
Initializing list
Print the original list
Define the length of the tuple list
Define the function Sort(for sorting tuple)
Set the key to performing sort
Print the result

Ex-1: b2)TUPLE Operations


Aim: Python program to join tuples if similar initial elements
Procedure:
A tuple list is created.
There is a definition for an empty list.
The iteration of the tuple list is tested to verify if the beginning items match.
The element is kept in the empty list if they match.
Otherwise, it is transformed to a tuple, then to a list, and finally to a list, before being put
in the empty list.

Ex-1: c)BOOK MAINTENANCE USING Dictionary


Aim: The program describes to access, deletes and add books of a Dictionary in Python.
Procedure:
A dictionary is created.
Dictionary is used to store data value in key value pairs.
Functions are created to access, delete and add books into the dictionary.
The menu is printed and the choice is taken from the user.
Call the function to choice taken from the user.
End the program
Ex- 2: a1) Python program to check the largest number among three.

Aim: Python program to check the largest number among three.

Procedure:

Start the program


Read the three integer values in num1, num2, and num3 (integer variables).
Check if num1 is greater than num2 and num3.
If true, then print ‘num1’ as the greatest number.
Then check, num2 is greater than num3.
If true, then print ‘num2’ as the greatest number.
If false, then print ‘num3’ as the greatest number.
Stop the program

Ex-2: a2) Program to check Prime number or not.

Aim:Python program to check whether the given number is prime or not.

Procedure:
Start the program
Read the number named num.
Check the given number is greater than 1
Then, use loop – range i from 1 to num.
If num mod i=0 then
Set f=0 and break else f=1
If f=0, print the given number is not prime
Else, print the given number is prime.

Ex- 2: a3) Program to find whether the given year is leap or not

Aim: Python program to check whether the given year is leap or not.

Procedure:
Step 1: Start the program
Step 2: Read the year named year.
Step 3: Check if mod of the given year with 100 is 0, else go to Step 6
Step 4: Then, mod the given year with 400 is 0, print Leap year
Step 5: Otherwise, print not leap year
Step 6: Check if mod of the given year with 4 is 0, print leap year
Step 7: Otherwise, print not leap year

Ex- 2: b1) Python program to find the given number is palindrome or not.

Aim: Python program to find the given number is palindrome or not.

Procedure:

Get the number from user.


Hold the number in temporary variable.
Reverse the number.
Compare the temporary number with reversed number.
If both numbers are same, print palindrome number.
Else print not palindrome number.

Ex- 2: b2) Python program to add two matrices using nested loop.

Aim: Python program toadd two matrices using nested loop.

Procedure:

Start the program


Declare a list that will store the matrix element and result
Iterate through the rows and columns
Add the corresponding elements in the two matrices and store them in the result list
Print the resultant list
Stop the program

Ex- 2: b3) Python program to find the sum of n numbers.

Aim: Python program tofind the sum of n numbers.

Procedure:

Start the program


Declare and initialize variable, value, num, sum=0.
Enter the value of num i.e. number upto which sum is to be calculated
Use Loop to add number. Any of while, do-while or for loop can be used.
Print the sum
Stop the program

Ex-3: VALIDATION OF PASSWORD - REGULAR EXPRESSION


Aim:Python program to check whether the password is valid or not with the help of few
conditions.

Procedure:
Start the program
Enter a password as input
using regular expression search() method to validate the password
First, check whether the password have minimum 8 characters or not.
Then check whether the alphabets must be between [a-z].
Having at least alphabet should be of Upper Case [A-Z].
Having at least one number or digit between [0-9].
Having at least one special character from [_ or @ or $].
Check any white space is in the input.

Ex- 4: CALENDAR FUNCTIONS


Aim: Python program to display the calendar and month using calendar function.

Procedure:
Start the program
Importing the calendar module
The menu is printed and the choice is taken from the user.
If choice is 1, read the year as input
Then the calendar function calendar.prcal() – display the calendar
If choice is 2, read the year and month as input
Use the calendar.month() function – display the month of the year.
Stop the program.

Ex-5: SIMPLE CALCULATION USING TKINTER


Aim: Using Python program for Simple calculation using tkinter

Procedure:
Importing the module – tkinter
Create the main window (container)
Create two three box for input and output
Create two button for implement the simple calculation
Stop the program

You might also like