Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 1 #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions Python-SMP/week-1/Nihar-Rai/qn 2 element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
find=[11,12,13,34,56,58,69,34]
position=[]
#finding position of 34
a=34
for i in range(0,len(find)):
if find[i]==a:
position.append(i+1)
print(position,sep=',')
print('are the positions of a')
8 changes: 8 additions & 0 deletions Python-SMP/week-1/Nihar-Rai/qn 2 sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sort=[1,2,3,6,3,7,5,8,2]
for i in range(0,len(sort)):
for j in range(0,len(sort)):
if sort[i]<sort[j]:
sort[i]=sort[i]+sort[j]
sort[j]=sort[i]-sort[j]
sort[i]=sort[i]-sort[j]
print(sort)
6 changes: 6 additions & 0 deletions Python-SMP/week-1/Nihar-Rai/qn 3 id check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
l1=[1,2,3]
l2=[1,2,3]
print(id(l1)==id(l2)) #False
str1='Good'
str2='Good'
print(id(str1)==id(str2)) #True
18 changes: 18 additions & 0 deletions Python-SMP/week-1/Nihar-Rai/qn1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
list1 = ['I','S','T','E']
list2 = list1 #list2 points at same object as 1
list2[0] ='1'#change in 0 position changes list1 too since same object is being used by both lists
print(list1)
list1 = list1 + []#item is added
list2[1] = 2
print(list1)
#Output1 ['1','S','T','E']
#output2 ['1','S','T','E']
list1 = ['I','S','T','E']
list2 = list1# same as above
list2[0] = '1'
print(list1)
list1+=[]# blank space is added to left of list1
list2[1] = 2
print(list1)#object list1 and 2 point to, are still same so all changes in list2are observed
#output1 ['1','S','T','E']
#output2 ['1',2,'T','E']
3 changes: 3 additions & 0 deletions Python-SMP/week-1/Nihar-Rai/qn4 cube root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
L=[1,15,3,14,13,10,16,17,19,120,26,47,58]
a=[]
for i in L: a+=( [i] if (i*i*i)%3==1 else [])