Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views2 pages

Exercise 3

The document contains five programming exercises in Python. It includes creating and concatenating tuples, counting vowels in a string, checking for a key in a dictionary, adding a new key-value pair, and summing all items in a dictionary. Each exercise is accompanied by code examples and expected output.

Uploaded by

Kancharagunta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Exercise 3

The document contains five programming exercises in Python. It includes creating and concatenating tuples, counting vowels in a string, checking for a key in a dictionary, adding a new key-value pair, and summing all items in a dictionary. Each exercise is accompanied by code examples and expected output.

Uploaded by

Kancharagunta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like