Exercise 1:
a = [45,12,53,2,35]
for j in range(len(a)-1):
if a[j] > a[j+1]:
t = a[j]
a[j] = a[j+1]
a[j+1] = t
for j in a:
print(j)
Exercise 2:
a = [45,12,53,2,35]
for i in range(len(a)-1):
for j in range(len(a)-1):
if a[j] > a[j+1]:
t = a[j]
a[j] = a[j+1]
a[j+1] = t
for j in a:
print(j)
Exercise 3:
a = [45,12,53,2,35]
for j in range(len(a)-1):
if a[0] > a[j+1]:
t = a[0]
a[0] = a[j+1]
a[j+1] = t
for j in a:
print(j)
Exercise 4:
a = [45,12,53,2,35]
for i in range(len(a)-1):
for j in range(i+1,len(a)):
if a[i] > a[j]:
t = a[i]
a[i] = a[j]
a[j] = t
for j in a:
print(j)
Homework:
a = [45,12,53,2,35]
for j in range(len(a)-1):
if a[j] > a[j+1]:
t = a[j]
a[j] = a[j+1]
a[j+1] = t
for j in a:
print(j)
[…] at List| |____Unit 31 More Operations on Lists| |____Unit 32 Common Algorithms for Lists| |____Unit 33 Bubble Sort and Selection Sort| |____Unit 34 Multidimensional Lists| |____Unit 35 Student Performance Management System (Part 1)| […]