EXERCISE-3
1.Write a program to create tuples(name,age,address,college) for atleast
two members and concatenate the tuples and print the concatenated tuples
m1=('ravi',12,'vijayawada','SRK')
m2=('ramu',11,'vijayawada','SRK')
t=m1+m2
print(t)
Output:
('ravi', 12, 'vijayawada', 'SRK', 'ramu', 11, 'vijayawada', 'SRK')
2.Write a program to count the number of vowels in a string
def count_vowels(text):
vowels = "aeiouAEIOU"
count = 0
for char in text:
if char in vowels:
count += 1
return count
user_input = input("Enter a string: ")
vowel_count = count_vowels(user_input)
print(f"Number of vowels in the string: {vowel_count}")
Output:
Enter a string: hEllaeo
Number of vowels in the string: 4
3. Write a program to check if a given Key exists in dictionary or not
my_dict={1:'a',2:'b',3:'c'}
if 2 in my_dict:
print("Present")
Output:
Present
4. Write a program to add a new Key-Value pair to an existing dictionary
my_dict = {'a': 10, 'b': 20, 'c': 30}
my_dict['d'] = 40
print("Updated dictionary:", my_dict)
Output:
Updated dictionary: {'a': 10, 'b': 20, 'c': 30, 'd': 40}
5.Write a program to sum all the items in a given dictionary
my_dict = {'a': 10, 'b': 20, 'c': 30, 'd': 40}
total_sum = sum(my_dict.values())
print("Sum of all items in the dictionary:", total_sum)
Output:
Sum of all items in the dictionary: 100