0% found this document useful (0 votes)
9 views15 pages

Practical

The document contains a series of Python programs demonstrating various operations on dictionaries and tuples, including summing values, popping elements, clearing dictionaries, merging, checking existence, and finding lengths. Each program includes source code, expected output, and user prompts for input. It concludes with a certificate of completion for Chetna Sharma's practical work in Computer Science.

Uploaded by

nr991950
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)
9 views15 pages

Practical

The document contains a series of Python programs demonstrating various operations on dictionaries and tuples, including summing values, popping elements, clearing dictionaries, merging, checking existence, and finding lengths. Each program includes source code, expected output, and user prompts for input. It concludes with a certificate of completion for Chetna Sharma's practical work in Computer Science.

Uploaded by

nr991950
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/ 15

-CERTIFICATE--CERTIFICATE- 1

-CERTIFICATE--CERTIFICATE- 2

PROGRAM 10

#WAP to Sum All Values in a


Dictionary
Source Code:
my_dict = {'a': 10, 'b': 20, 'c': 30}
total sum = sum (my_dict. Values ()
print("Sum of all values in the
dictionary:", total_sum)
Output:
Sum of all values in the dictionary:
60
-CERTIFICATE--CERTIFICATE- 3

PROGRAM 9
#Write a program to Pop an
Element from a Dictionary
Source Code:
my_dict = {'name': 'John', 'age': 25, 'city':
'New York'}
popped_value = my_dict.pop('age')
print("Popped Value:", popped_value)
print("Updated Dictionary:", my_dict)
Output:
Popped Value: 25
Updated Dictionary: {'name': 'John', 'city':
'New York'}
-CERTIFICATE--CERTIFICATE- 4

PROGRAM 8
#Write a program to clear
all elements from a
dictionary
Source Code:
my_dict = {'name': 'John', 'age': 25,
'city': 'New York'}
my_dict.clear()
print("Cleared Dictionary:",
my_dict)
Output:
Cleared Dictionary: {}
-CERTIFICATE--CERTIFICATE- 5

PROGRAM 7
#Write a program to merge
two dictionaries
Source Code:
dict1 = {'name': 'Alice', 'age': 30}
dict2 = {'city': 'London', 'job':
'Engineer'}
dict1.update(dict2)
print("Merged Dictionary:", dict1)
Output:
Merged Dictionary: {'name': 'Alice',
'age': 30, 'city': 'London', 'job':
'Engineer'}
-CERTIFICATE--CERTIFICATE- 6

PROGRAM 6
# Write a program to check
if an item exists in a tuple
Source Code:
my_tuple = (10, 20, 30, 40, 50) item_to_check
= 30
if item_to_check in my_tuple:
print(f"{item_to_check} exists in the tuple.")
else:
print(f"{item_to_check} does not exist in the
tuple.")
Output:
30 exists in the tuple.
-CERTIFICATE--CERTIFICATE- 7

PROGRAM 5
# write a program to find
the length of a tuple
Source Code:
my_tuple = (1, 2, 3, 4, 5)
length = len(my_tuple)
print("Length of the tuple:", length)

Output:
Length of the tuple: 5
-CERTIFICATE--CERTIFICATE- 8

PROGRAM 4
#Write a program to input a
tuple and check if it contains
the all elements as same.
Source Code:
tup = eval(input("Enter a tuple: "))
In = len(tup)
num=tup.count(tup[0])
if num == 1n:
print("Tuple contains all the same elements.")
else:
print("Tuple contains different elements.")
Output:
Enter a tuple: 23,23,23,23
-CERTIFICATE--CERTIFICATE- 9

PROGRAM 3
#Write a program to print
the index of the minimum
element in a tuple.
Source code:
tup = eval(input("Enter a tuple : "))
mn = min(tup)
print("Minimum element", mn,\
"is at index", tup.index(mn))
Output:
Enter a tuple 23, 22, 11, 9, 10, 15
Minimum element 9 is at index 3
-CERTIFICATE--CERTIFICATE- 10

PROGRAM 2

#Write a program to print a tuple's


first three and last manner:
Source Code:
t1 eval(input("Enter input for tuple: "))
print(t1[0], t1[-1])
print(t1[1], t1[-2])
print(t1[2], t1[-3])
Output:
Enter input for tuple: 11, 12, 13, 14, 15, 16,
17, 18, 19
11 19
12 18
13 17
-CERTIFICATE--CERTIFICATE- 11

PROGRAM 1
#Write a program to create a tuple
with a single input value.

Source code:
t1 = eval(input("Enter input for tuple: "))
print("Created tuple is:", t1)

Output:
Enter input for tuple: 67,
Created tuple is: (67,)
2025/2/10 21:21
-CERTIFICATE--CERTIFICATE- 12

-CERTIFICATE-
This is to certify that
Chetna Sharma of class
XI-A has completed her
Practical in Session
2024-25 as per the
prescribed practical
syllabus under the
guidance of Asha Sharma
Ma’am and submitted for
the practical
examination held on 17
Feb 2025
-CERTIFICATE--CERTIFICATE- 13

Yours Truly
Chetna Sharma
-CERTIFICATE--CERTIFICATE- 14

Computer Science
Practical-II

CHETNA SHARMA
XI-A

Balvantray Mehta vidhya bhawan

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy