-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAss1.py
More file actions
224 lines (154 loc) · 3.39 KB
/
Ass1.py
File metadata and controls
224 lines (154 loc) · 3.39 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
'''q3'''
string="I am a computer science student"
print(string[0:1])
print(string[1:6])
print(string[2:])
print("\n")
'''q5'''
L1=[1,2,3]
L2=[4,5,6]
L1.extend(L2)
for i in L1:
print(i, end="")
print("\n")
for j in L1:
if(j%2==0):
print(j,end="")
print("\n")
'''q6'''
tup1=(1,2,"hello","world",8.9)
for i in tup1:
print(i)
print("\n")
tup2=("programming",)
tup3=tup2*3
print(tup3)
print("\n")
tup4=("hello","world","hi")
tupResult=tup4+tup3
for i in tupResult:
print(i)
print("\n")
'''q7'''
person={"first_name":"John","last_name":"Doe","age":25,"favourite_colors":["blue","green"],"active":True}
for key in person:
print(key,":",person[key])
print(person.keys())
print("\n")
print(person.values())
print("\n")
print(person["last_name"])
print("\n")
'''q8'''
n=int(input("Enter a number"))
if n%2==0:
print("even")
else:
print("odd")
print("\n")
'''q10'''
n=int(input("Enter the length"))
L=[]
for i in range(0,n):
num=int(input("Enter a number"))
L.append(num)
Frq={}
Lfinal=[]
for item in L:
if item in Frq:
Frq[item] += 1
else:
Frq[item] = 1
for i in Frq:
if Frq[i]==1:
Lfinal.append(i)
for i in Lfinal:
print(i)
print("\n")
'''q12'''
inventory={"Item1":2,"Item2":3,"Item3":4,"Item4":5,"Item5":0}
inventory["Item6"]=0
for key in inventory:
print(key,":",inventory[key])
if inventory[key]==0:
print("Out of stock")
else:
print("In stock")
'''q13'''
def calculate_rectangle_area(length=1,width=1):
return length*width
length=4
width=5
print("Area of rectangle is:",calculate_rectangle_area(length,width))
print("\n")
print("Area of rectangle is:",calculate_rectangle_area(6,7))
print("\n")
print("Area of rectangle is:",calculate_rectangle_area(4))
print("\n")
'''q14'''
def Global_Local():
global Value
Value=100
print("Inside function: ",Value)
Value=50
print("Before function: ",Value)
Global_Local()
print("Outside function: ",Value)
print("\n")
'''q15'''
def process_student_data(L):
newDict={}
for student in L:
avgscore=0
for i in student["grades"]:
avgscore+=i
newDict[student["id"]]=avgscore/len(student["grades"])
return newDict
students=[
{"id":1,"grades":[90,85,95],"name":"Stude1"},
{"id":2,"grades":[80,90,75],"name":"Stude2"},
{"id":3,"grades":[95,85,90],"name":"Stude3"},
{"id":4,"grades":[90,85,76],"name":"Stude4"}
]
students[3]["grades"]=[98,76,90]
newDict=process_student_data(students)
print(process_student_data(students))
print("\n")
for student_id, avg_grade in newDict.items():
if avg_grade >= 90:
print(student_id, ":", avg_grade)
'''q1'''
a=5
print(a,type(a))
print("\n")
b=6
print(a+b,b-a,a*b,a/b)
print("\n")
s1="hi"
print(len(s1))
print("\n")
# num=int(s1)
# print(num)
# print("\n")
'''q2'''
a=6
b=9
print("Temp Var")
temp=a
a=b
b=temp
print("a:",a,"b:",b)
print("Without")
b=b-a
a=a+b
b=a-b
print("a:",a,"b:",b)
'''q4'''
my_list = [10, 20, 30, 50, 60, 70]
print("Initial List:", my_list)
print("Elements from the third position to the end:", my_list[2:])
middle_index = len(my_list) // 2
my_list.insert(middle_index, 40) # Insert 40 into the middle
my_list.append(100) # Append 100 to the end
print("List after inserting 40 in the middle and appending 100 at the end:", my_list)
print("Third, fourth, and fifth elements of the list:", my_list[2:5])