python unit-3 programs
Program-1:
Aim: Write a program to create tuples
(name, age, address, college) for at least two members and concatenate the
tuples and print the concatenated tuples.
Program:
t1=('revanth',19,'vijayawada','LBRCE
college')
t2=('kumar',20,'mylavaram','CMR
college')
con_tuple=t1+t2
print(con_tuple)
output:
program-2:
Aim: Write a program to count the number
of vowels in a string (No control flow allowed).
Program:
string="pythonprogramming"
vowel_count=len([char
for char in string if char in 'aeiouAEIOU'])
print(vowel_count)
output:
program-3:
Aim : Write a program to check
if a given key exists in a dictionary or not.
Program:
dict={'a':1,'b':2,'c':3}
check='b'
exists=check
in dict
print(exists)
output:
program-4:
Aim: Write a program to add a new key-value
pair to an existing dictionary
Program:
dict={'a':1,'b':2}
dict['c']=3
print(dict)
output:
program-5:
Aim: Write a program to sum all the items
in a given dictionary.
Program:
dict={'a':10,'b':20,'c':30}
total_sum=sum(dict.values())
print(total_sum)
output:
Comments
Post a Comment