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

procedure

The document outlines various programming tasks including flow control, functions, string manipulation, operations on lists, tuples, sets, dictionaries, and classes. It also covers method overloading, file handling, regular expressions, modules, packages, and exception handling. Each section provides step-by-step instructions for implementing specific functionalities in programming.

Uploaded by

udccssanthiya
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

procedure

The document outlines various programming tasks including flow control, functions, string manipulation, operations on lists, tuples, sets, dictionaries, and classes. It also covers method overloading, file handling, regular expressions, modules, packages, and exception handling. Each section provides step-by-step instructions for implementing specific functionalities in programming.

Uploaded by

udccssanthiya
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

a) FLOW CONTROL

Step 1:Ask the user to enter a number n and store it.

Step 2: If n is 0 or 1, return 1.

Step 3: If n > 1, call the function fact(n-1).

Step 4: Multiply n by the result of fact(n-1) and return the value.

Step 5: Print the number and its factorial.

1.b)FUNCTIONS

Step 1:Prompt the user to enter a string and store it in variable s.

Step 2: Reverse the string s and store the result in variable rev.

Step 3: Compare the original string s with the reversed string rev.

Step 4: If the original string s is equal to the reversed string rev, return True (indicating it is a
palindrome). Otherwise, return False.

Step 5: Based on the return value, print "yes" if it is a palindrome or "no" if it is not.

1.C)STRING MANIPULATION

Step 1: Assign "hello world" to variable a.

Step 2: Print the length of a using len(a).

Step 3: Assign "Hello, world!" to a and print a.upper().

Step 4: Assign "Hello, World!" to a and print a.lower().

Step 5: Assign "hello" to a, "world" to b, concatenate them as c = a + b, and print c.

2.A)OPERATION ON LIST

Step 1:Create two lists: list1 containing mixed data types and list2 containing integers.
Step 2: Print the contents of list1 and list2.

Step 3: Print a slice of list1 from index 1 to 4 (exclusive).

Print a slice of list1 from index 2 to the end.

Step 4: Print the result of concatenating list1 and list2.

Step 5: Print the lengths of both lists using len().

Step 6: Print the maximum value in list2 using max().

Step 7: Print the values in list2 before appending a new value.

Append the value 100 to list2 and print the updated list.

2.B)OPERATION ON TUPLE

Step 1:Initialize Tuples:

Step 2: Print `tupple1` and `tupple2`.

Step 3: Print `tupple1[1:4]` (elements from index 1 to 4).

Print `tupple1[2:]` (elements from index 2 to end).

Step 4: Print `tupple2 * 2` (repeat `tupple2`).

Print `tupple1 + tupple2` (concatenate the tuples).

Step 5: print Length and Maximum Value

3.OPERATION ON SET

Step 1: Create two sets:

Step 2: Perform Union

Step 3: Perform Intersection

Step 4: Perform Difference


Step 5: Add and Pop Operations

4.OPERATION ON DICTIONARY

Step 1: Create a dictionary dict1 with the following key-value pairs:

'name': 'Veeraragavan','age': 70,'Hight': 170

Step 2: Print Initial Dictionary

Step 3: Create a second dictionary dict2 with a key-value pair: 'weigth': 96

Step 4: Update First Dictionary

Step 5: Clear the Dictionary

5.OPP CONSTRUCTOR PROGRAM

Step 1: Create a class named Car.

Define a class variable wheels and set it to 4.

Step 2: Define the __init__ method to initialize the object's attributes:

Step 3: Define a method named showDescription:

 Define a method named changeColor:

Step 4: Create an object c of the Car class:

Step 5: Call the showDescription method on object c to display its initial description.

Change the color of the car by calling changeColor with the new color 'white'.

Call the showDescription method again to display the updated description.

6.METHOD OVERLOADING

Step 1: Create a class named example.


Step 2: Define the first method add with parameters a and b

Step 3: Define the second method add with parameters x and y

Step 4: Prompt the user to input values for a, b, x, and y:

Step 5: Create an instance of the example class.

Call the first add method with a and b.

Call the second add method with x and y.

7.FILE HANDLING PROGRAM

Step 1: Define Function to Create a File

Step 2: Define Function to Read a File

Step 3: Define Function to Append to a File

Step 4: Define Functions to Rename and Delete a File

Step 5: Main Program Execution

8.REGULAR EXPRESSION

Step 1:Import the regular expression module with import re.

Step 2: Define the Text and Pattern

Step 3: Search for the Pattern

 Use re.search(pattern, text) to search for the defined pattern in the text.
 Store the result in a variable named result.

Step 4: Check for Matches

 Use an if statement to check if result is not None:


o If a match is found, print the starting index of the pattern using result.start().

o If no match is found, print "pattern not found".


Step 5: Stop

9.MODULE CONCEPT

Step 1: Accept three values from the user:

Step 2: Determine if the number n falls within the range defined by the lower limit a and
the upper limit b.

Step 3: Compare If n is within the range [a, b), proceed to the next step.

If n is not in the range, declare it out of range.

Step 4: Print a message stating whether the number n is in the range or out of the range.

Step 5: End Program

10.PACKAGE PROGRAM

Step 1: Define Function A

 Define a function a() in module A that prints "Hello from A".

Step 2: Define Function B

 Define a function b() in module B that prints "Hello from B".

Step 3: Define Function C

 Define a function c() in module C that prints "Hello from C".

Step 4: Import Functions from Modules

 Import the function a() from module A, b() from module B, and c() from module C.

Step 5: Main Program Execution

 Call the functions A.a(), B.b(), and C.c() to print the respective messages "Hello from A",
"Hello from B", and "Hello from C".

11.EXCEPTION HANDLING
Step 1: Prompt the user to enter two numbers, a and b.

o Perform the division operation result = a / b.

Step 2: Use an except block to catch a ZeroDivisionError and print an error message if the
second number is zero.

Step 3: Use an else block to print the result of the division if no exception occurred.

Step 4: Define a function display(s) that:

o Attempts to convert the argument s to an integer using try.


o Catches a ValueError in an except block and prints an error message if the
conversion fails.

Step 5: Use a try block to attempt adding a number to a string. Catch the TypeError in an except
block and print the error message along with the exception details.

You might also like