0% found this document useful (0 votes)
6 views2 pages

Python Problems 28.10.2024

Uploaded by

atlazxh16
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
6 views2 pages

Python Problems 28.10.2024

Uploaded by

atlazxh16
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 2

Python problems 28.10.

2024

#Bubble sort
arr = [2, 1, 0, -3, -7, 9, 4, 18, -35]
n = len(arr)

for i in range(n - 1):


for j in range(n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]

print(arr)

#Insertion sort
arr = [2, 1, 0, -3, -7, 9, 4, 18, -35]
n = len(arr)

for i in range(1, n):


j = i

while j > 0 and arr[j] < arr[j - 1]:


arr[j], arr[j - 1] = arr[j - 1], arr[j]
j -= 1
print(arr)
print("----------------------------")

#Selection sort
arr = [64, 25, 12, 22, 11]
n = len(arr)

for i in range(n - 1):


min_index = i

for j in range(i + 1, n):


if arr[j] < arr[min_index]:
min_index = j

arr[i], arr[min_index] = arr[min_index], arr[i]

print(arr)

#Numbers
n = int(input())
dp = [0] * 31
dp[1] = 2
dp[2] = 4
for i in range(3, 31):
dp[i] = dp[i - 1] + dp[i - 2]
print(dp[n])

#Sieve of Eratosthenes
n = int(input())
A = [1] * (n + 1)
A[0] = 0
A[1] = 0
i = 2
while i*i <= n:
if A[i] == 1:
for j in range(i*i, n + 1, i):
A[j] = 0
i += 1
for k in range(n + 1):
if A[k] == 1: print(k, end=' ')

1. if elif
2. for while
3. Siyahi(sort, search)
4.Ikiolchulu siyahi
5. Setir tipleri(str)
eolymp saytindan her movzuya aid 10 sualin hellini
tedqimat faylina yazmaq

You might also like