8000 assignment · machphy/python_programming_@559ee1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 559ee1b

Browse files
committed
assignment
1 parent 49d7a19 commit 559ee1b

15 files changed

+105
-0
lines changed

SIC_assignment/Dictionary_Creation.py

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)

SIC_assignment/Dictionary_Update.py

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))

SIC_assignment/Nested_Structures.py

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))

SIC_assignment/Recursive_Function.py

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)

SIC_assignment/Set_from_Dictionary.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def unique_grades(student_grades):
2+
all_grades = set()
3+
for grades in student_grades.values():
4+
all_grades.update(grades)
5+
return all_grades
6+
7+
8+
grades_dict = {"John": [85, 90], "Jane": [78, 85], "Doe": [78, 92]}
9+
print(unique_grades(grades_dict))

SIC_assignment/Tuple_Creation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
countries = ("India", "USA", "France", "Germany", "Australia")
2+
3+
for country in countries:
4+
print(country)

SIC_assignment/Tuple_Indexing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def get_second_and_fourth(t):
2+
return t[1], t[3]
3+
4+
numbers = (10, 20, 30, 40, 50)
5+
second, fourth = get_second_and_fourth(numbers)
6+
print("Second:", second)
7+
print("Fourth:", fourth)

SIC_assignment/Tuple_Unpacking.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def tuple_sum_and_product(t):
2+
first_two_sum = t[0] + t[1]
3+
last_two_product = t[1] * t[2]
4+
return first_two_sum, last_two_product
5+
6+
test_tuple = (3, 4, 5)
7+
sum_result, product_result = tuple_sum_and_product(test_tuple)
8+
print("Sum of first two:", sum_result)
9+
print("Product of last two:", product_result)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def tuples_to_dict(tuples_list):
2+
return {name: age for name, age in tuples_list}
3+
4+
5+
name_age_tuples = [("John", 25), ("Jane", 22), ("Doe", 30)]
6+
print(tuples_to_dict(name_age_tuples))

0 commit comments

Comments
 (0)
0