Условные операторы:x = 10 if x > 5: print("x is greater than 5") elif x == 5: print("x is equal to 5") else: print("x is less than 5")Циклы:# Цикл while i = 0 while i < 5: print(i) i += 1 # Цикл for for i in range(5): print(i)Функции:def add_numbers(a, b): return a + b result = add_numbers(10, 5) print(result)Списки:fruits = ["apple", "banana", "cherry"] fruits.append("strawberry") print(fruits) for fruit in fruits: print(fruit)Словари:person = { "name": "John", "age": 30, "city": "New York" } print(person["name"]) person["age"] = 31 print(person)Массивы:import numpy as np array = np.array([1, 2, 3, 4, 5]) print(array) mean = np.mean(array) print(mean)Сортировка:numbers = [4, 2, 7, 1, 9] sorted_numbers = sorted(numbers) print(sorted_numbers) numbers.sort() print(numbers)
Это основные алгоритмические конструкции на языке программирования Python.
if x > 5:
print("x is greater than 5")
elif x == 5:
print("x is equal to 5")
else:
print("x is less than 5")Циклы:# Цикл while
i = 0
while i < 5:
print(i)
i += 1
# Цикл for
for i in range(5):
print(i)Функции:def add_numbers(a, b):
return a + b
result = add_numbers(10, 5)
print(result)Списки:fruits = ["apple", "banana", "cherry"]
fruits.append("strawberry")
print(fruits)
for fruit in fruits:
print(fruit)Словари:person = {
"name": "John",
"age": 30,
"city": "New York"
}
print(person["name"])
person["age"] = 31
print(person)Массивы:import numpy as np
array = np.array([1, 2, 3, 4, 5])
print(array)
mean = np.mean(array)
print(mean)Сортировка:numbers = [4, 2, 7, 1, 9]
sorted_numbers = sorted(numbers)
print(sorted_numbers)
numbers.sort()
print(numbers)
Это основные алгоритмические конструкции на языке программирования Python.