1. Генератор Mad Libs



Yüklə 42,3 Kb.
səhifə5/9
tarix09.09.2023
ölçüsü42,3 Kb.
#142167
növüПрограмма
1   2   3   4   5   6   7   8   9
python primeri1

Пример кода:
# Recursive Binary Search algorithm in Python

def binarySearch(array, x, low, high):

if high >= low:

mid = low + (high - low)//2

# If found at mid, return the value

if array[mid] == x:

return mid

# Search the first half



elif array[mid] > x:

return binarySearch(array, x, low, mid-1)

# Search the second half



else:

return binarySearch(array, x, mid + 1, high)

else:

return -1

array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

x = int(input("Enter a number between 1 and 10:"))

result = binarySearch(array, x, 0, len(array)-1)



if result != -1:

print("Element is present at position" + str(result))



else:

print("Element not found")


6. Калькулятор 
Этот проект научит вас разрабатывать графический интерфейс и является хорошим способом познакомиться с библиотекой, такой как Tkinter. Эта библиотека позволяет создавать кнопки для выполнения различных операций и отображения результатов на экране.
Пример кода:
# Calculator

def addition ():

print("Addition")

n = float(input("Enter the number: "))

t = 0 #Total number enter

ans = 0

while n != 0:

ans = ans + n

t+=1

n = float(input("Enter another number (0 to calculate): "))



return [ans,t]

def subtraction ():

print("Subtraction");

n = float(input("Enter the number: "))

t = 0 #Total number enter

sum = 0

while n != 0:

ans = ans - n

t+=1

n = float(input("Enter another number (0 to calculate): "))



return [ans,t]


Yüklə 42,3 Kb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin