Something
Something
2(a)
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)
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)
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)
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)
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.