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

ASSIGNMENT4 Python

Uploaded by

PAVAN
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)
7 views

ASSIGNMENT4 Python

Uploaded by

PAVAN
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
You are on page 1/ 4

113220561

PAVAN DANGE

ASSIGNMENT 4

List1=(22,24,26,28,["apple","banana","kiwi","chico","dragonfrut"],1,2,"MITWPU","PUNE")

print(List1)

print(List1[8:])

print(List1[4][1])

element = List1[-4]

print(element)

print(List1[:2])

print(List1[-3:])

#Q2

list1 = ["Rose", "Lily", "Tulip", "Daisy", "Vatsal", 5, 10, 3.4, 4.5]

list2 = ["Apple", "Banana", "Mango", "Orange", "Grapes", "2104010", 15, 20]

print(list1)

print(list2)

list1.append("MITWPU")

print(list1)

list2.append("Pune")

print(list2)

print(list1+list2)

print(list1*3)

list1.insert(3, "SoCS")

print(list1)

#Q3.
List3 = (11, 33, 22, 11, 11, 22, 33, "Bsccs", 'SoCS')

print(List3)

number=List3.index('Bsccs')

print(number)

num11=List3.count(11)

print(num11)

#Q4.

# Example using a list

List1 = [22, 24, 26, 28, ["apple", "banana", "kiwi", "chico", "dragonfrut"], 1, 2, "MITWPU", "PUNE"]

print("Original List1:", List1)

List1.clear()

print("Cleared List1:", List1)

int_list = [10, 20, 30, 40, 50]

print("List of Integers:", int_list)

mixed_list = [1, "hello", 3.14, True, None]

print("List with Mixed Data Types:", mixed_list)

nlist = ["mitwpu", [2, 0, 1, 5]]

print("Element at index 0 of the outer list:", nlist[0])

print("Element at index 3 of the inner list:", nlist[1][3])

l1 = ['p', 'r', 'o', 'b', 'e']

print("Item at index -1:", l1[-1])

print("Item at index -2:", l1[-2])


print("Item at index -3:", l1[-3])

# Q1: Sum of List Items

list_items = [1, 2, 3, 4, 5]

print("Sum of List items:", sum(list_items))

# Q2: Read 10 Numbers and Print List

numbers = []

for _ in range(10):

numbers.append(int(input("Enter a number: ")))

print("Numbers entered so far:", numbers)

# Q3: Exclude First and Last Two Elements

user_list = list(map(int, input("Enter numbers separated by spaces: ").split()))

print("New list excluding first and last two elements:", user_list[2:-2] if len(user_list) > 4 else "Not
possible")

# Q4: Read 5 Numbers and Print in Reverse Order

numbers = [int(input("Enter a number: ")) for _ in range(5)]

print("Input data:", numbers)

numbers.reverse()

print("Printing values from the list in reverse order:")

print('\n'.join(map(str, numbers)))

# Q5: Square Each Item in List

list1 = [1, 2, 3, 4, 5, 6, 7]

squared_list = [x**2 for x in list1]

print("Squared list:", squared_list)


# Q6: Remove Empty Strings from List

given_list = ["hey", "there", "", "what's", "", "up", "", "?"]

given_list = list(filter(None, given_list))

print("Original List:", ["hey", "there", "", "what's", "", "up", "", "?"])

print("Modified List:", given_list)

You might also like