Python Practical - (3, 4)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Aim: 3.a.

A pangram is a sentence that contains all the letters of the English


alphabet at least once, for example: The quick brown fox jumps over the lazy
dog. Your task here is to write a function to check a sentence to see if it is a
pangram or not.

Program:
import string,sys

if sys.version_info[0] < 3 :
input = raw_input
def ispangram(sentence, alphabet = string.ascii_lowercase):
alphabet = set(alphabet)
return alphabet <= set (sentence.lower())
print (ispangram(input('sentence :')))
Outout:-
Aim: 3.b. Take a list, say for example this one: a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] and
write a program that prints out all the elements of the list that are less than 5.

Program:-

name= 'Harsh'
print( name)
list = [1,2,3,4,5,8,13,21,34,55,89]
New_list = []
for i in list:
if i < 5:
New_list.append(i)
print (New_list)

Output:-
Aim: 4.a. Write a program that takes two lists and returns True if they have at least one
common member.

Program:-

#Method – 1
list1 = [1,2,3,4,5]
list2 = [4,5,6,7,8]
for i in list1:
for j in list2:
if i==j:
print('Both the list have the element ',i, 'in ccommon')
Output:-
Aim: 4.b. Write a Python program to print a specified list after removing the 0th, 2nd, 4th and
5th elements.

Program:-

list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


print ('Original list is :', list)
print ("Now we have remove 0th-1, 2nd – 3, 4th – 5 and 5th – 6 elements")
list.remove(list[0])
print(list) #2,3,4,5,6,7,8,9,10
list.remove(list[1])
print(list) # 2,4,5,6,7,8,9,10
list.remove(list[2])
print(list) # 2,4,6,7,8,9,10
list.remove(list[2])
print(list) # 2,4,7,8,9,10
Output:-
Aim: 4.c. Write a Python program to clone or copy a list.

Program:-
list = [21,45,66,7,51,79]

clone = list.copy()

print ('Original list : ' , list)

print ('Clone list : ', clone)

Output:-

You might also like