Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions week1assignment-govardhan/assignment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
1)
a:
list1 = [ 'I' , 'S' , 'T' , 'E' ]
list2 = list1
list2[0] = '1'
print(list1)
list1 = list1 + []
list2[1] = 2
print(list1)
OUTPUT:
['1', 'S', 'T', 'E']
['1', 'S', 'T', 'E']
B: list1 = [ 'I' , 'S' , 'T' , 'E' ]
list2 = list1
list2[0] = '1'
print(list1)
list1 + =[]
list2[1] = 2
print(list1)
OUTPUT:
['1', 'S', 'T', 'E']
['1', 2, 'T', 'E']
since list1 and list2 are equalised,any change in the one of the list makes
automatically change in the other list.
therefore,list2[0]="1 will also change the value in list1 also
list1=list1+[] and list1+=[] are different
because, by using list1+[] will not change the values in the list2 of same
indev,whreas by using list1+=[] will change the values of both lists,if one is
changed

2)
a=[1,324,5,657,3,8,97,96,54,57,34]
for i in range(0,len(a)-1):
for j in range(i+1,len(a)):
if(a[i]>a[j]):
a[i],a[j]=a[j],a[i]
print(a)
def search(b,h):
p=0
for i in range(0,len(h)):
If(b==h[i]):
p=1
else:
p=0
if(p==1):
Page 1
GOVA
print("found")
else:
print("not found")
search(68,a)
OUTPUT:
[1, 3, 5, 8, 34, 54, 57, 96, 97, 324, 657]
not found
3)
l1 = [1,2,3]
l2 = [1,2,3]
print(id(l1) == id(l2))
str1='Good'
str2='Good'
print(id(str1) == id(str2))
OUTPUT:
False
True
4)
a=[x for x in range(1,500,1)]
b=[]
i=0
while(i<len(a)):
if(((a[i]*a[i]*a[i])%3-1)==0):
b.append(a[i])
i=i+1
print(b)
OUTPUT:
[1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52,
55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109,
112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157,
160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 205,
208, 211, 214, 217, 220, 223, 226, 229, 232, 235, 238, 241, 244, 247, 250, 253,
256, 259, 262, 265, 268, 271, 274, 277, 280, 283, 286, 289, 292, 295, 298, 301,
304, 307, 310, 313, 316, 319, 322, 325, 328, 331, 334, 337, 340, 343, 346, 349,
352, 355, 358, 361, 364, 367, 370, 373, 376, 379, 382, 385, 388, 391, 394, 397,
400, 403, 406, 409, 412, 415, 418, 421, 424, 427, 430, 433, 436, 439, 442, 445,
448, 451, 454, 457, 460, 463, 466, 469, 472, 475, 478, 481, 484, 487, 490, 493,
496, 499]