Chiziqli algaritmlarni dasturlash.
1-misol: Trapetsiyaning ikkita asosi (a va b) hamda asosiga tushurilgan balandligi (h) berilgan. Trapetsiyaning yuzi s ni hisoblash dasturini tuzing.
Yechish:
a=int(input("trapetsiyaning kichik asosini kiriting ="))
b=int(input("trapetsiyaning katta asosini kiriting ="))
h=int(input("trapetsiyaning balandligini kiriting ="))
s=(a+b)/2*h
print("trapetsiyaning yuzi =",s,"ga teng")
2-misol:Teng tomonli uchburchakning tomoni a ga teng.Uning yuzi s ni hisoblash dasturini tuzing.
Yechish:
a=int(input("uchburchak tomonini kiriting ="))
s=(3**(1/2))/4*(a**2)
print("uchburchak yuzi ",s,"ga teng")
3-misol:Kvadratning tomoni a ga teng.Uning yuzi s ni hisoblash dasturini tuzing.
Yechish:
a=int(input("kvadrat tomonini kiriting ="))
s=pow(a,2)
print("kvadrat yuzi ",s,"ga teng")
Tarmoqlanuvchi algaritmlarni dasturlash.IF…ELSE operatorlari
1-misol: Kiritilgan a soni musbat yoki manfiy ekanligini aniqlovchi dastur tuzing
Yechish:
print('sonni kiriting')
a=int(input())
if a>0:
print('kiritilgan son musbat son')
else:
print('Kiritilgan son manfiy son')
2-misol Kiritilgan son juf yoki toq ekanligini aniqlovchi dastur tuzing
Yechish:
print("sonni kiriting")
a=int(input())
if a%2==0:
y="bu son juft son"
else:
y="bu son toq son"
print(y)
3-misol Tomonlari a va b bo’lgan to’g’ri to’rtburchakni kvadrat ekanini aniqlovchi dastur tuzing
Yeshich:
print("sonni kiriting")
a=int(input())
b=int(input())
if a==b:
y="Bu shakl kvadrat"
else:
y="Bu shakl kvadrat emas"
print(y)
4-misol :Kiritilgan a soni to’rt xonali son ekanligini xisoblovchi dastur tuzing
Yechish:
print('sonni kiriting')
a=int(input())
if a//1000>=1 and a//1000<=9:
print('Kiritilgan son tort xonali son')
else:
print('kiritilgan son 4 xonli son emas')
5-misol Ikkita a va b son berilgan.Agar b son a sondan kichik bo’lsa,u holda b ni “0” bilan almashtiruvchi,aks holda b ni o’zgarishsiz qoldiruvchi dastur tuzing
Do'stlaringiz bilan baham: |