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

assignment1.txt #19

Open
wants to merge 1 commit 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
95 changes: 95 additions & 0 deletions AyushBhandariNITK/Week-1/assignment1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
1

In the first one
First output:

['1','S','T','E']

['1','S','T','E']

Reason is that list2=list1 create same object so change in list2 will also create change in list1.

After that list1=list1+[] will create new object for list1.
So that will change in list2 will not create change in list1.

Second output:

['1','S','T','E']

['1',2,'T','E']

Here for first one reason is same that list2=list1

Here, list1=list1+[] will not create new object for list1.
So again change in list2 will affect list1


2
a=[2,3,4,6,5,7,1,8]
print(a)

b=0

e=0

while(b!=len(a)):

for i in range(b,8):

if(a[i]<a[b]):

c=a[b]

a[b]=a[i]

a[i]=c
b+=1

print(a)

print("Which element tou want to find?")

d=int(input())

for i in range(0,len(a)):
if(a[i]==d):

e=1

break

if(e==1):
print("Element is found and position =",i)

else:
print("Element is not found")


3

Output:

False

True

l1 and l2 are different object.
Both str1 and str2 are same object.
4
a=int(input("How many number you want ?"))

b=[]

for i in range(0,a):

b.append(int(input("Enter number")))

print(b)

print("Numbers following condition are")

for i in range(0,a):

if((b[i]**3)%3==1):

print(b[i])
95 changes: 95 additions & 0 deletions AyushBhandariNITK/assignment1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
1

In the first one
First output:

['1','S','T','E']

['1','S','T','E']

Reason is that list2=list1 create same object so change in list2 will also create change in list1.

After that list1=list1+[] will create new object for list1.
So that will change in list2 will not create change in list1.

Second output:

['1','S','T','E']

['1',2,'T','E']

Here for first one reason is same that list2=list1

Here, list1=list1+[] will not create new object for list1.
So again change in list2 will affect list1


2
a=[2,3,4,6,5,7,1,8]
print(a)

b=0

e=0

while(b!=len(a)):

for i in range(b,8):

if(a[i]<a[b]):

c=a[b]

a[b]=a[i]

a[i]=c
b+=1

print(a)

print("Which element tou want to find?")

d=int(input())

for i in range(0,len(a)):
if(a[i]==d):

e=1

break

if(e==1):
print("Element is found and position =",i)

else:
print("Element is not found")


3

Output:

False

True

l1 and l2 are different object.
Both str1 and str2 are same object.
4
a=int(input("How many number you want ?"))

b=[]

for i in range(0,a):

b.append(int(input("Enter number")))

print(b)

print("Numbers following condition are")

for i in range(0,a):

if((b[i]**3)%3==1):

print(b[i])