1.Write a python program to define a function to check a sentence and see if it is a pangram or not.
for example: The quick brown fox jumps over the lazy dog.
2.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.
Practical 3a : Write a python program to define a function to check a sentence and see if it is a pangram or not.
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..
"""
Author : ITVoyagers (https://itvoyagers.in)
Date :09th August 2018
Description : Write a python program to define a function to check a sentence and see if it is a pangram or not.
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.
"""
def pangram(itv):
#check is variable containining all 26 alphabets
check="abcdefghijklmnopqrstuvwxyz"
for letter in check:
if(letter in itv):
continue
else:
return False
return True
string=input("Enter Any Text:")
if(pangram(string.lower())):
#string.lower() will convert any string from user to lower
#so we do not need upper case letters in check variable
print("Yes It is a Pangram")
else:
print("No It is not a Pangram")
OUTPUT
>>>
Enter Any Text:site name is itvoyagers
No It is not a Pangram
>>> ================================ RESTART ================================
>>>
Enter Any Text:The quick brown fox jumps over the lazy dog
Yes It is a Pangram
>>>
Practical 3b : 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.
"""
Author : ITVoyagers (https://itvoyagers.in)
Date :09th August 2018
Description : 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.
"""
def lessthanfive(li,itv):
#using list comprehension
new_list = [ele for ele in li if ele < itv]
return new_list
list1 = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
print("The list is ", str(list1))
#u=you can take value for itv from user to make code dynamic
#itv=int(input("Enter a value to check values less than it"))
itv=5
new_list = lessthanfive(list1,itv)
print ("New list having less than 5 values is",new_list)
OUTPUT
>>>
The list is [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
New list having less than 5 values is [1, 1, 2, 3]