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

Assignments 2 in BNCET

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)
10 views2 pages

Assignments 2 in BNCET

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

Sets

1. Set Creation: Create a set containing the first 10 prime numbers. Print the set and its
length.
2. Set Operations: Given two sets, A = {1, 2, 3, 4} and B = {3, 4, 5, 6}, find the union,
intersection, and difference of the two sets.
3. Set Membership: Write a function that takes a set and an element as arguments and
returns True if the element is in the set; otherwise, return False.

Tuples

4. Tuple Creation: Create a tuple containing the names of five different countries. Print
each country using a loop.
5. Tuple Indexing: Given a tuple of numbers (10, 20, 30, 40, 50), write a function that
returns the second and fourth elements of the tuple.
6. Tuple Unpacking: Write a function that takes a tuple of three elements and returns the
sum of the first two and the product of the last two.

Dictionaries

7. Dictionary Creation: Create a dictionary that maps five countries to their capitals. Print
the capital of one specific country.
8. Dictionary Update: Write a function that adds a new key-value pair to a given dictionary
and returns the updated dictionary.
9. Dictionary Iteration: Given a dictionary of student names and their scores, write a
function that prints each student’s name along with their score, sorted by score in
descending order.

Functions

10. Function with Default Argument: Write a function that takes a number and a default
multiplier (e.g., 2) and returns the product. Test the function with and without providing
the multiplier.
11. Recursive Function: Write a recursive function to calculate the factorial of a given
number.
12. Lambda Function: Create a lambda function that takes a list of numbers and returns a
new list containing only the even numbers.

Combined Concepts

13. Nested Structures: Create a list of tuples, where each tuple contains a student's name
and their score. Write a function that returns a dictionary mapping each student’s name to
their score.
14. Set from Dictionary: Given a dictionary where keys are student names and values are
lists of grades, write a function that returns a set of all unique grades.
15. Tuple and Dictionary: Write a function that takes a list of tuples (name, age) and returns
a dictionary where names are keys and ages are values.

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