0% found this document useful (0 votes)
4 views

XI_Programming Activity(Part 1)

The document outlines a series of programming activities in Python focusing on lists, tuples, dictionaries, and modules. Each activity includes specific tasks such as performing operations on lists, calculating mean and frequency, manipulating tuples, and using dictionaries for various operations. Additionally, it covers using the math and random modules for mathematical computations and generating random numbers.

Uploaded by

rio161218
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)
4 views

XI_Programming Activity(Part 1)

The document outlines a series of programming activities in Python focusing on lists, tuples, dictionaries, and modules. Each activity includes specific tasks such as performing operations on lists, calculating mean and frequency, manipulating tuples, and using dictionaries for various operations. Additionally, it covers using the math and random modules for mathematical computations and generating random numbers.

Uploaded by

rio161218
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
You are on page 1/ 5

Programming Activity

Topics:List,Tuples,Dictionary and Python modules

Lists in Python:

Activity 1: List Operations

Create a list of 10 random numbers.

Perform the following operations on the list:

■​ Concatenate another list of 5 numbers to the list.


■​ Repeat the list 3 times.
■​ Check if a number exists in the list (membership operation).
■​ Slice the list to extract the first 5 elements.
■​ Sort the list in ascending order.

Output the final modified list.

Hints:

Use extend(), append(), sort(), and slicing.

Activity 2: List Traversal and Frequency Count

Write a Python program to traverse a list and count the frequency of each element in the
list.

Print the frequency of each element.

Example Input:​
numbers = [1, 2, 3, 2, 3, 3, 4, 5, 1]
Example Output:​

Frequency of 1: 2
Frequency of 2: 2
Frequency of 3: 3
Frequency of 4: 1
Frequency of 5: 1

Activity 3: Find Mean of List


Create a list of numbers and calculate the mean (average) of the list.

Hints:

Use sum() and len() functions.

Example Input:​

numbers = [10, 20, 30, 40, 50]
Example Output:​
Mean: 30.0

Tuples in Python:

Activity 4: Tuple Operations

Create a tuple of numbers.

Perform the following operations:

■​ Concatenate another tuple.


■​ Repeat the tuple 2 times.
■​ Access an element by index and slice the tuple.
■​ Use count() to find the frequency of a particular number.

Output the results.

Hints:

Use slicing, concatenation, and repetition.

Activity 5: Minimum, Maximum, and Mean of Tuple

Create a tuple with numeric values and find the minimum, maximum, and mean
of the values in the tuple.

Hints:

Use min(), max(), and sum() functions.

Calculate mean using sum(tuple) / len(tuple).


Example Input:​
numbers = (10, 20, 30, 40, 50)
Example Output:​
Min: 10
Max: 50
Mean: 30.0

Dictionaries in Python:

Activity 6: Dictionary Operations

Create a dictionary with keys as employee names and values as their salaries.

Perform the following:

■​ Add a new employee with their salary.


■​ Update the salary of an existing employee.
■​ Access the salary of a specific employee using the get() method.
■​ Delete an employee from the dictionary.

Print the final dictionary.

Example Input:​

employees = {'John': 5000, 'Alice': 6000, 'Bob': 7000}
Example Output:​
{'John': 5000, 'Alice': 6000, 'Bob': 7000, 'Eve': 8000}

Activity 7: Count Occurrences of a Character in a String Using Dictionary

Write a Python program that takes a string as input and counts how many times
each character appears in the string using a dictionary.

Example Input:​
text = "programming"
Example Output:​

{'p': 1, 'r': 2, 'o': 1, 'g': 2, 'a': 1, 'm': 2, 'i': 1, 'n': 1}
Activity 8: Copy and Clear Dictionary

Create a dictionary, copy it to another dictionary, and clear the original dictionary.

Output the contents of both dictionaries before and after clearing.

Hints:

Use copy() and clear() methods.

Example Input:​

dict1 = {'a': 1, 'b': 2}
dict2 = dict1.copy()
Example Output:​
dict1: {'a': 1, 'b': 2}
dict2: {'a': 1, 'b': 2}
dict1 after clear: {}
dict2 after clear: {'a': 1, 'b': 2}

Python Modules:

Activity 9: Using the math Module

Import the math module and use it to calculate:

■​ Square root of a number.


■​ The value of pi.
■​ Power of a number.
■​ Round a number to the nearest integer.

Example:​

import math
print(math.sqrt(16)) # Output: 4.0
print(math.pi) # Output: 3.141592653589793
Activity 10: Using the random Module

Write a program that generates 5 random integers between 1 and 100.

Find the maximum, minimum, and sum of these random numbers.

Hints:

Use randint() and randrange() functions from the random module.

Example:​

import random
numbers = [random.randint(1, 100) for _ in range(5)]
print(f"Numbers: {numbers}")
print(f"Max: {max(numbers)}, Min: {min(numbers)}, Sum:
{sum(numbers)}")

Activity 11: Statistics on List Using statistics Module

Write a program that uses the statistics module to compute the mean,
median, and mode of a list of numbers.

Example Input:​
import statistics
numbers = [10, 20, 30, 20, 30, 40]
Example Output:​

Mean: 25
Median: 25.0

Mode: 20

You might also like