1 topshiriq.
Aylananing r radiusi berilgan. Uning yuzini topish funksiyasini
tuzing.
Masalaning qo’yilishi. Berilgan r radiusi aylananing yuzini topish funksiyasi
tuzilib. Bu funksiyaga murojaat qilamiz.
Pythonda dastur tuzilishi:
def aylana_yuzi(r):
pi=3.14
yuz=pi*r*r
return yuz
radius=int(input(“Aylana radiusini kiriting:”))
aylana_yuzi=aylana_yuzi(radius)
print(“Aylana yuzi:”, aylana_yuzi)
Aylana radiusini kiriting: 5
Aylana yuzi: 78.5
Dasturda aylana_yuzi nomli funksiyani yaratdik, funksiya parametri r ga teng.
Aylana yuzi
𝑠 = 𝜋𝑟
2
3 qatoriga keltirilgan. Dastur tanasida funksiyaga murojjat etib
berilgan qiymat bo’yicha aylana yuzi hisoblanadi.
2 topshiriq.
Ixtiyoriy 4 ta son berilgan, uning ichida eng katta sonni topish
dasturi tuzilsin.
Masalaning qo’yilishi. Ikkita sondan eng kattasini topish funksiyasini tuzamiz
va dastur tanasida funksiyaga murojjat qilamiz. Ikkita sondan eng kattasini topishda if
else operatoridan foydalanamiz.
105
Pythonda dastur tuzilishi:
def katta_son(x, y):
if x>y: kat=x
else: kat=y
return kat
#dastur tanasi
a=int(input(‘a son kiriting =’))
b=int(input(‘b son kiriting =’))
c=int(input(‘c son kiriting =’))
d=int(input(‘d son kiriting =’))
n=kata_son(a,b)
m=kata_son(c,d)
eng_katta=katta_son(n,m)
print(‘Eng katta son =’, eng_katta)
a son kiriting =5
b son kiriting =8
c son kiriting =42
d son kiriting =16
Eng katta son 42
3 topshiriq.
Berilgan a (haqiqiy) sonining k (butun) darajasini topuvchi dastur
tuzing. Buning uchun daraja (a, k) funksiyasini yarating
Masalaning qo’yilishi. Ixtiyoriy haqiqiy sonni butun darajasini topish uchun
funksiya tuzamiz va bu funksiyaga qiymat berib echimni topamiz
Pythonda dastur tuzilishi:
def daraj(x, y):
nat=x**y
return nat
a=float(input(‘a soniniga qiymat kiriting =’))
k=float(input(‘k soniniga qiymat kiriting =’))
natija=daraj(a,k)
print(“Berilgan sonning darjasi =”, natija)
a soniniga qiymat kiriting
=5.5
k ning qiymatini kiriting =2
Berilgan sonning darjasi =
30.25
106
4 topshiriq.
Hisoblang. Y=
т
х
х
х
1
...
1
1
1
2
;
from math import *
def func (x,y):
z=sqrt(1+x**y)
return z
s=0
n=int(input(‘n=’))
a=int(input(‘a=’))
for i in range (n)
s+=func(a, i)
print(“s=”, s)
n=10
a=3
s= 331.6443046236192
Dostları ilə paylaş: |