9 - Amaliy mashg’ulot
Axborotlar oqimini segmentlarga ajratish. Dinamik dasturlash. CHiziqli model.
Boshlash
Kiritish X
For x in range(2,8,2)
X**2
print(x)
Tugatish
juftlar = [x for x in range(2, 8,2)] #2 dan 8 gacha juft sonlarni hisoblaymiz
kvadratlar = [x**2 for x in juftlar] #ularni darajaga kotaramiz
yigindi = sum(kvadratlar) # qoshish amalini bajaramiz
print(yigindi) # natijani chiqarish
10 - Amaliy ish uchun topshiriqlar
Jarayon matematik modelini tuzishda eng kichik kvadratlar usulidan foydalanish. Kvadratik, teskari proporsional bog‘lanish modellari
For I in range (a, b+1)
a, b, x
boshlash
if num % x == 0
Yoq
sum_divisible_numbers = sum
product_divisible_numbers *= num
Xa
Print(Natija)
tugatish
a = 10 # a va b o'zgaruvchilarni e'lon qilib, ularga qiymat beramiz
b = 20
x = 5
# a va b orasidagi sonlarni topish
numbers = [] #numbers degan bo'sh ro'yxat yaratamiz
for i in range(a, b+1): #a dan b gacha bo'lgan barcha sonlarni numbers ro'yxatiga qo'shamiz
numbers.append(i)
# x ga bo'linadigan sonlarni topish
divisible_numbers = [] #divisible_numbers degan bo'sh ro'yxat yaratamiz
for num in numbers:
if num % x == 0: #agar numbers ro'yxatidagi son x ga qoldiqsiz bo'linsa, divisible_numbers ro'yxatiga qo'shamiz
divisible_numbers.append(num)
# yig'indini hisoblash
sum_divisible_numbers = sum(divisible_numbers) #divisible_numbers ro'yxatidagi barcha sonlarning yig'indisini hisoblaymiz
# ko'paytmasini hisoblash
product_divisible_numbers = 1
for num in divisible_numbers:
product_divisible_numbers *= num
print("Yig'indisi:", sum_divisible_numbers) #Natijalarni ekranga chiqaramiz
print("Ko'paytmasi:", product_divisible_numbers)
Dostları ilə paylaş: |