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

Something

The document outlines five Python programming exercises, each with a specific aim and algorithm. The exercises include removing elements from a list, finding the longest word in a list, retrieving specific elements from a tuple, checking for a key in a dictionary, and finding maximum and minimum values in a set. Each exercise concludes with a statement confirming successful execution and verification of the program.

Uploaded by

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

Something

The document outlines five Python programming exercises, each with a specific aim and algorithm. The exercises include removing elements from a list, finding the longest word in a list, retrieving specific elements from a tuple, checking for a key in a dictionary, and finding maximum and minimum values in a set. Each exercise concludes with a statement confirming successful execution and verification of the program.

Uploaded by

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

Ex No.

2(a)

REMOVE ELEMENTS IN LIST


18/08/2021

AIM:

To write a Python program to print a specified list after removing the 0th, 4th and
5th elements.

ALGORITHM:
STEP 1: Start the program
STEP 2: Create a list
STEP 3: Using for loop and enumerate function remove 0th, 4th, 5th elements
STEP 4: Print the list after removing elements
STEP 5: Stop

PROGRAM:

OUTPUT:

RESULT:
Thus, the given program has been executed and verified successfully.
Ex No. 2(b)

LONGEST WORD IN THE LIST


18/08/2021

AIM:
To write a Python function that takes a list of words and returns the longest word
and the length of the longest one.

ALGORITHM:

Step 1 : First declare a function with the name ‘longest Length ‘ which accepts a list
as an argument.
Step 2 : Now, take a list where you have all the values.
Step 3 : We are going to take this list, and we will iterate through each item using
for loop.
Step 4 : Then we take two variables max1 and temp to store the maximum length
and the word with the longest length.
Step 5 : After completing the above steps then we take the first value in the list and
the first value length in order to compare.
Step 6 : Once the above steps are completed we compare the items in the list using
for loop. Below I had mentioned the logic.
Step 7 : After completing the above steps run the program, and then we’ll get the
required result.
Step 8 : End.

PROGRAM:
OUTPUT:

RESULT:
Thus, the given program has been executed and verified successfully.
Ex No. 2(c)

GETTING DESIRED ELEMENT IN A TUPLE


18/08/2021

AIM:
To write a python program to get the 4th element and 4th element from last of
a tuple.

ALGORITHM:
Step 1 : Start.
Step 2 : Create tuple with desired elements.
Step 3 : To get item (4th element) of the tuple by index,
Step 4 : Define the index values as 3 which fetches the 4th element in the
tuple.
Step 5 : Print the item.
Step 6 : To get item (4th element from the last) by negative indexing.
Step 7 : Define the index value as -4.
Step 8 : Print the item.
Step 9 : End.
PROGRAM:

OUTPUT:

RESULT:
Thus, the given program has been executed and verified successfully.
Ex No. 2(d)

CHEKING KEY IN A DICTIONARY


18/08/2021

AIM:
To write a python program to check whether a given key already exists in a
dictionary.
ALGORITHM:
Step 1 : Start.
Step 2 : Create a dictionary with keys and their
values.{1:10,2:20,3:30,4:40,5:50,6:60}.
Step 3 : With if condition if x in d,
Step 4 : Print The key is present in the dictionary.
Step 5 : Else,
Step 6 : Print the key is not present in the dictionary.
Step 7 : End.

PROGRAM :

OUTPUT :

RESULT:
Thus, the given program has been executed and verified successfully.
Ex No. 2(e)

MAXIMUM AND MINIMUM VALUE IN A SET


18/08/2021

AIM:
To write a python program to find the maximum and the minimum value in a set.

ALGORITHM:
Step 1 : Start.
Step 2 : Create set elements.{5,10,15,20,25,30,35,40,45,50}
Step 3 : Print the original set elements.
Step 4 : Print set and the set type.
Step 5 : Print the maximum value in a set.
Step 6 : Print the minimum value in a set.
Step 7 : End

PROGRAM:

OUTPUT:

RESULT:
Thus, the given program has been executed and verified successfully.

You might also like