Skip to content

Commit 559ee1b

Browse files
committed
assignment
1 parent 49d7a19 commit 559ee1b

15 files changed

+105
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Dictionary mapping countries to capitals
2+
country_capitals = {
3+
"India": "New Delhi",
4+
"USA": "Washington D.C.",
5+
"France": "Paris",
6+
"Germany": "Berlin",
7+
"Australia": "Canberra"
8+
}
9+
10+
11+
print("Capital of France:", country_capitals["France"])
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def print_sorted_students(scores_dict):
2+
sorted_students = sorted(scores_dict.items(), key=lambda x: x[1], reverse=True)
3+
for name, score in sorted_students:
4+
print(f"Student: {name}, Score: {score}")
5+
6+
student_scores = {"John": 85, "Jane": 90, "Doe": 78, "Alice": 92}
7+
print_sorted_students(student_scores)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def add_key_value_pair(d, key, value):
2+
d[key] = value
3+
return d
4+
5+
my_dict = {"India": "New Delhi", "USA": "Washington D.C."}
6+
updated_dict = add_key_value_pair(my_dict, "Canada", "Ottawa")
7+
print(updated_dict)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def multiply(number, multiplier=2):
2+
return number * multiplier
3+
4+
print(multiply(5))
5+
print(multiply(5, 3))

SIC_assignment/Lambda_Function.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
even_numbers = lambda numbers: [num for num in numbers if num % 2 == 0]
2+
3+
4+
test_list = [1, 2, 3, 4, 5, 6]
5+
print(even_numbers(test_list))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def map_students_to_scores(student_list):
2+
return {name: score for name, score in student_list}
3+
4+
5+
students = [("John", 85), ("Jane", 90), ("Doe", 78)]
6+
print(map_students_to_scores(students))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def factorial(n):
2+
if n == 1:
3+
return 1
4+
else:
5+
return n * factorial(n - 1)
6+
7+
print(factorial(5))

SIC_assignment/Set_Creation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
prime_numbers = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}
3+
print("Set of prime numbers:", prime_numbers)
4+
print("Length of the set:", len(prime_numbers))

SIC_assignment/Set_Membership.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def is_element_in_set(s, elem):
2+
return elem in s
3+
4+
my_set = {1, 2, 3, 4, 5}
5+
print(is_element_in_set(my_set, 3))
6+
print(is_element_in_set(my_set, 6))

SIC_assignment/Set_Operations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
A = {1, 2, 3, 4}
2+
B = {3, 4, 5, 6}
3+
4+
union_set = A.union(B)
5+
print("Union:", union_set)
6+
7+
intersection_set = A.intersection(B)
8+
print("Intersection:", intersection_set)
9+
10+
11+
difference_set = A.difference(B)
12+
print("Difference (A - B):", difference_set)

0 commit comments

Comments
 (0)