0% found this document useful (0 votes)
3 views13 pages

Nikhil Goyal Python Exp5

The document outlines a Python programming experiment focusing on lists, tuples, and dictionaries. It includes various tasks such as counting occurrences of values, calculating averages, finding runner-up scores, and creating applications like a contact book and a todo list manager. Additionally, it provides theoretical explanations of data structures and expected learning outcomes for students.

Uploaded by

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

Nikhil Goyal Python Exp5

The document outlines a Python programming experiment focusing on lists, tuples, and dictionaries. It includes various tasks such as counting occurrences of values, calculating averages, finding runner-up scores, and creating applications like a contact book and a todo list manager. Additionally, it provides theoretical explanations of data structures and expected learning outcomes for students.

Uploaded by

abhinavbhattuk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NAME - NIKHIL GOYAL

SAP ID - 590026332
BATCH - 26

PYTHON PROGRAMMING
Experiment 4
AIM:LIST , TUPLE , DICTIONARY
1. Scan n values in range 0-3 and print the number of times each
value has
occurred.

2. Create a tuple to store n numeric values and find average of all


values.

3. WAP to input a list of scores for N students in a list data type.


Find the score of
the runner-up and print the output.
Sample Input
N=5
76
Scores= 2 3 6 6 5
Sample output
5
Note: Given list is [2, 3, 6, 6, 5]. The maximum score is 6, second
maximum is 5. Hence, we print 5 as the runner-up score.

4. Create a dictionary of n persons where key is name and the


value is the city.
a) Display all names
b) Display all city names
c) Display student name and city of all students.
d) Count the number of students in each city.
5. Store details of n movies in a dictionary by taking input from the
user. Each
movie must store details like name, year, director name, production
cost,
collection made (earning) & perform the following :-
a) print all movie details
b) display name of movies released before 2015
c) print movies that made a profit.
d) print movies directed by a particular director.

6. Create a contact book where users can store, search, update,


and delete contacts. Use a dictionary for storing contacts.

7. Create a Todo list Manager where users can add, view, and
remove tasks. Use
List for storing tasks.
theory , learning outcomes
THEORY

1. List

A list is an ordered and mutable collection of elements enclosed in


square brackets [ ]. Lists can store elements of different data types
and allow duplicate values. Since lists are mutable, elements can be
added, removed, or modified after creation.

Lists support various built-in methods such as:

●​ append() – to add an element


●​ remove() – to delete an element
●​ sort() – to arrange elements
●​ len() – to find number of elements

Lists are commonly used for storing student scores, managing tasks in a
todo list, and counting occurrences of values.

2. Tuple

A tuple is an ordered but immutable collection of elements enclosed in


parentheses ( ).

Characteristics:

●​ Allows duplicates
●​ Cannot modify elements after creation
●​ Indexed

Tuples are used when:

●​ Data should not change


●​ Performing calculations like average
3. Dictionary

A dictionary is a collection of key-value pairs enclosed in curly braces {


}. Each key is unique and is used to access its corresponding value.

Dictionary methods include:

●​ keys() – returns all keys


●​ values() – returns all values
●​ items() – returns key-value pairs
●​ get() – retrieves value using key
●​ pop() – removes a key-value pair

Dictionaries are useful for storing structured data such as contact books
(name → phone number), movie details (movie → information), and
person-city mappings.
PYTHON CODE
5.1)

OUTPUT:
5.2)

OUTPUT:
5.3)

OUTPUT:
5.4)

OUTPUT:
5.5)

OUTPUT:
5.6)

OUTPUT:
5.7)

OUTPUT:
LEARNING OUTCOMES
After completing this experiment, students will be able to:

1.​ Understand the concept of lists, tuples, and dictionaries in Python.


2.​ Differentiate between mutable and immutable data types.
3.​ Perform operations like insertion, deletion, searching, and sorting
in lists.
4.​ Store and retrieve data using key-value pairs in dictionaries.
5.​ Implement logical programs such as:

i)Counting frequency of elements .

ii)Finding runner-up score.

iii)Calculating average.

6.​ Apply nested dictionaries for real-world data storage.


7.​ Design mini applications like:

i)Contact Book

ii)Todo List Manager

iii)Movie Database

8.​ Improve logical thinking and problem-solving skills using Python


data structures.
9.​ Use built-in functions and methods effectively.
10.​ Develop structured and modular programs.

You might also like