
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















rd
Department of Information and Communication Technology Chaudhary Bansilal University, Bhiwani (Haryana)
INDEX Sr. No.
No. Remarks 1 Program to sum all the items in a list. 03 2 Program to multiply all the items in the list 04 3 Program to get the largest number in the list 05 4 Program to access the index of a list. 06 5 Program to get the difference between the two lists. 07 6 Program to clone or copy a list. 08 7 Program to remove duplicate from a list. 09 8 Program to check a list is empty or not. 10 9 Program to find the list of word that are longer than n from a given list of words. 11 10 Program to create a function with variable length of arguments 12 11 Write a Python function that takes two list and return True if they have atleast one common number. 13 12 Program to print a specified list after removing the 0th,4th,and 5th elements. 14 13 Program to shuffle and print a specified list. 15 14 Program to create a Simple Program Using Class and Objects 16 15 Program to create a class to find sum and difference of two numbers using inheritance 17 16 Program to generate and print a list of first and last 5 elements where the values are square of number between 1 and 30. 18 17 Program to generate and print a list except for the first 5 elements, where the value are square of number between 1 and
19 18 Program to draw a star using Python Turtle 20 19 Program to draw a color filled Circle using Python Turtle 21 20 Program to create an app with widgets Using Tkinter 22
new_list(list):
product = 1 for i in list: product = product * i return product list1 = [23, 12, 4, 8] print(list1) print("Product:") print(new_list(list1))
[23, 12, 4, 8] Product: 8832
#List of numbers listA = [10, 30, 5, 75, 9, 66] #Printing the largest number in a list print("Largest number is : " , max(listA))
Largest number is : 75
def Diff(list1, list2): list_dif = [i for i in list1 + list2 if i not in list1 or i not in list2] return list_dif list1 = [20, 10, 30, 35, 15, 40] list2 = [10, 5, 40, 25] list3 = Diff(list1, list2) print(“ Difference : “,list3)
Difference: [20, 30, 35, 15, 5, 25]
def Cloning(list1): list_copy = list1[:] return list_copy list1 = [2, 4 ,6, 8, 16, 10, 12] list2 = Cloning(list1) print("Original List : " , list1) print("After Cloning : ", list2)
Original List : [2, 4, 6, 8, 16, 10, 12] After Cloning : [2, 4, 6, 8, 16, 10, 12]
list1 = [12, 3, 67] if not list1: print("The list is empty") else: print("The list is not empty")
The list is not empty
def long_words(n, str): word_len = [] txt = str.split(" ") for x in txt: if len(x) > n: word_len.append(x) return word_len print(long_words(3, "Life is a succession of lessons"))
['Life', 'succession', 'lessons']
def multiply(*args):
def common_data(list1, list2): result = False for x in list1: for y in list2: if x == y: result = True return result return result print(common_data([1,2,3,4,5],[5,6,7,8,9])) print(common_data([1,2,3,4,5], [6,7,8,9]))
True False
th
th
th
['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
the original list
color = [x for (i, x) in enumerate(color) if i not in (0, 4, 5)]
print(color)
['Green', 'White', 'Black']
from random import shuffle animal = ["Cat", "Dog", "Elephant", "Fox", "Tiger", "Lion", "Panda"] shuffle(animal) print(“Specified list : “,animal)
bike1.name = "Mountain Bike" print(f"Name: {bike1.name}, Gears: {bike1.gear} ")
Name: Mountain Bike, Gears: 11
class First: def input1(self): self.x = int(input("Enter first number:")) class Second: def input2(self): self.y = int(input("Enter second number:"))
class Third(First, Second): def add(self): super().input1() super().input2() self.z = self.x + self.y print("Sum is:", self.z) obj = Third() obj.add()
Enter first number: 43 Enter second number: Sum is: 98
def printValues(): # Create an empty list 'A' A = list()
for i in range(1, 21):
A.append(i**2)
print(A[:5])
[36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900]