Repository navigation
Expand file tree
/
Copy pathIRWA_Lab_01.py
More file actions
115 lines (99 loc) · 2.69 KB
/
Copy pathIRWA_Lab_01.py
File metadata and controls
115 lines (99 loc) · 2.69 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Question 01
teams = ["India", "England", "NZ", "Aus"]
captains = ["Kohli", "Root", "Williaamson", "Smith"]
# print(list(zip(teams, captains)))
# print(dict(zip(teams, captains)))
# Question 02
books = ["textbooks", "exercise books", "story book", "drawing books"]
prices = [100, 60, 90, 70]
quantities = [3, 2, 1, 4]
for book, price, quantity in zip(books, prices, quantities):
total = price * quantity
print(f"You bought {quantity} {book} for ${total}")
# Question 03
list1 = [2, 4, 6, 8, 10]
result = [x + 10 for x in list1]
print(result)
# Question 04
list1 = [10, 20, 30, 40]
list2 = ["Apples", "Mangoes", "Oranges", "Grapes"]
for a, b in zip(list1, reversed(list2)):
print(a, b)
# Question 05
list1 = ["a", "b", ["c", ["d", "e", ["f", "g"], "k"], "l"], "m", "n"]
sub_list = ["h", "i", "j"]
list1[2][1][2].extend(sub_list)
print(list1)
# Question 06
list1 = [10, 15, 20, 15, 32, 54, 15]
result = [x for x in list1 if x != 15]
print(result)
# Question 07
dict_1 = {'John': 15, 'Rick': 10, 'Misa': 12}
dict_2 = {'Bonnie': 18, 'Rick': 20, 'Matt': 16}
dict_1.update(dict_2)
print(dict_1)
# Question 08
d = {0: 0, 1: 1, 2: 2, 3: 3}
d[4] = d.pop(0)
print(d)
# Question 09
country = ["USA", "France", "India"]
capital = ["Washington D.C.", "Paris", "New Delhi"]
result = dict(zip(country, capital))
print(result)
# Question 10
My_dict = {
"Fruit": "Pear",
"Vegetable": "Carrot",
"Pet": "Cat",
"Book": "Moby dick",
"Crystal": "Amethyst"
}
keysToRemove = ["Book", "Crystal"]
for key in keysToRemove:
My_dict.pop(key, None)
print(My_dict)
# Question 11
sub_dict = {'math': 100, 'chem': 98, 'sci': 100, 'eng': 100}
key_to_extract = {'math', 'chem', 'sci'}
result = {k: sub_dict[k] for k in key_to_extract}
print(result)
# Question 12
list1 = [12, 15, 32, 42, 55, 75, 122, 132, 150, 180, 200]
result = [x for x in list1 if x % 5 == 0]
print(result)
# Question 13
numbers = [12, 75, 150, 180, 145, 525, 50]
for num in numbers:
if num > 500:
break
if num > 150:
continue
if num % 5 == 0:
print(num)
# Question 14
text = "@W3Resource.Com"
upper = lower = digit = special = 0
for ch in text:
if ch.isupper():
upper += 1
elif ch.islower():
lower += 1
elif ch.isdigit():
digit += 1
else:
special += 1
print("Upper case characters:", upper)
print("Lower case characters:", lower)
print("Number case:", digit)
print("Special case characters:", special)
# Question 15
n = 5
num = ''
total = 0
for i in range(n):
num += '2'
total += int(num)
print(num, end='+')
print(f"\nSum of above series is: {total}")