XI_Programming Activity(Part 1)
XI_Programming Activity(Part 1)
Lists in Python:
Hints:
Write a Python program to traverse a list and count the frequency of each element in the
list.
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
Hints:
Example Input:
numbers = [10, 20, 30, 40, 50]
Example Output:
Mean: 30.0
Tuples in Python:
Hints:
Create a tuple with numeric values and find the minimum, maximum, and mean
of the values in the tuple.
Hints:
Dictionaries in Python:
Create a dictionary with keys as employee names and values as their salaries.
Example Input:
employees = {'John': 5000, 'Alice': 6000, 'Bob': 7000}
Example Output:
{'John': 5000, 'Alice': 6000, 'Bob': 7000, 'Eve': 8000}
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.
Hints:
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:
Example:
import math
print(math.sqrt(16)) # Output: 4.0
print(math.pi) # Output: 3.141592653589793
Activity 10: Using the random Module
Hints:
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)}")
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