-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathassignment_6_12_2021.py
59 lines (44 loc) · 1.55 KB
/
assignment_6_12_2021.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 1. create a list and find the average of that list using numpy
import numpy as np
num_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
avg = np.mean(num_list)
print(avg)
# 2. create a nested dictionary
def nested_dict():
nested_dict = {'key1': {'key2': {'key3': 'value'}}}
print(nested_dict)
nested_dict()
# 3. create a list and find the median value
num_list_2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
median = np.median(num_list_2)
print(median)
# 4. what is the output of the following code?
# l = [None] * 10
# print(len(l))
10
# 5. Briefly explain Bubble Sort and Insertion Sort and selection sort algorithms.
# Bubble sort is a sorting algorithm that compares each pair of adjacent items and swaps them if they are in the wrong order.
# Insertion sort is a sorting algorithm that builds the final sorted array (or list) one item at a time.
# Selection sort is a sorting algorithm that sorts the items by selecting the next item each time and putting it in the correct position.
# 6. What is the output of the following code?
# aList = [5, 10, 15, 25]
# print(aList[::-2])
[25, 10]
# 7. What is the output of the following code?
my_list = ["Hello", "Python"]
print("-".join(my_list))
# Hello-Python
# 8. A python tuple can also be created using paranthesis(True or False)
# True
# 9. What is the output of the following code?
# aTuple = "Yellow", 20 , "Red"
# a,b,c = aTuple
# print(a)
# Yellow
# 10. Please select the answer in the code to empty the following dictionary
# student = {
# "name": "Emma",
# "class": 9,
# "marks": 75
# }
# student.clear()