9 – SINF INFORMATIKA VA AXBOROT TEXNOLOGIYALARI DARSLIGIDA BERILGAN TOPSHIRIQLAR YECHIMLARI
#48-dars. AMALIY MASHG‘ULOT
#1.Uchta a, b va c butun son berilgan. Ular orasidan #musbatlari sonini topish dasturini tuzing.
#48-dars 1-mashq
a=int(input('a='))
b=int(input('b='))
c=int(input('c='))
s=0
if a>0:
s+=1
if b>0:
s+=1
if c>0:
s+=1
print('musbat sonlar',s,'ta')
input()
#48-dars 2-mashq
#2.Uchta a, b va c butun son berilgan. Ular orasidan #musbat va manfiylari sonini topish dasturini tuzing.
a=int(input('a='))
b=int(input('b='))
c=int(input('c='))
mus=0
man=0
if a>0:
mus+=1
if a==0:
man==man
if a<0:
man+=1
if b>0:
mus+=1
if b==0:
man==man
if b<0:
man+=1
if c>0:
mus+=1
if c==0:
man==man
if c<0:
man+=1
print('mus=',mus,'man=',man)
input()
#48-dars 3-mashq
#3.Ikkita a va b son berilgan. Dastlab kattasini, keyin #esa kichigini chiqaruvchi dastur tuzing.
a=int(input('a='))
b=int(input('b='))
if a>b:
print(a,b)
else:
print(b,a)
input()
#48-dars 4-mashq
#4.Uchta a, b va c butun son berilgan. Ulardan faqat #musbatlari kvadratini hisoblab chiquvchi dastur tuzing.
a=int(input('a='))
b=int(input('b='))
c=int(input('c='))
if a<=0:
a=0
else:
a=a*a
if b<=0:
b=0
else:
b=b*b
if c<=0:
c=0
else:
c=c*c
s=a+b+c
print(a,b,c)
input()
#48-dars 5-mashq
#5.Kvadrat tenglamani yechish dasturini tuzing.
a=int(input('a='))
b=int(input('b='))
c=int(input('c='))
D=b*b-4*a*c
from math import*
if D>=0:
x1=(-b-sqrt(D))/(2*a)
x2=(-b+sqrt(D))/(2*a)
print('x1=',x1,'x2=',x2)
else:
print('yechimga ega emas')
input()
#48-dars 6-mashq
#6.Hafta raqami 1–7 oraliqda kiritilganda, hafta kunini #ekranga chiqaruvchi dastur tuzing.
a=int(input('Xaftaning nechanch kuni'))
if a==1:
print('Dushanba')
if a==2:
print('Seshanba')
if a==3:
print('Chorshanba')
if a==4:
print('Payshanba')
if a==5:
print('Juma')
if a==6:
print('Shanba')
if a==1:
print('Yakshanba')
f a<1 or a>7:
print('Bunday kun yo`q')
input()
#48-dars 7-mashq
#7.a va b sonlar berilgan. Agar ular musbat va yig‘indisi #100 dan katta bo‘lsa, a sonining b songa nisbatini, ular #musbat va yig‘indisi 100 dan katta bo‘lmasa, a ning b ga #ko‘paytmasini hisoblash dasturini tuzing.
a=int(input('a='))
b=int(input('b='))
c=a+b
if a>0 and b>0 and c>100:
s=a/b
if a>0 and b>0 and c<=100:
s=a*b
print(s)
input()
#48-dars 8-mashq
#8.Ikkita son berilgan. Agar birinchi son ikkinchisidan katta #bo‘lsa, 1 ni, agar ikkinchi son birinchisidan katta bo‘lsa,
#2 ni, agar ikkalasi teng bo‘lsa, 0 ni chiqaruvchi dastur tuzing.
a=int(input('a='))
b=int(input('b='))
if a>b:
print(a)
if b>a:
print(b)
if a==b:
print(0)
#49–50-darslar. TAKRORLANUVCHI ALGORITMLARNI DASTURLASH. #FOR OPERATORI
#49-dars 1-topshiriq
#1.a va b sonlar berilgan. a dan b gacha bо‘lgan barcha #sonlarni chiqaruvchi dastur tuzing. Bu yerda a <= b.
print('a<=b shartni bajaruvchi a va b sonlarini kiriting ')
a=int(input('a='))
b=int(input('b='))
if a>b:
print('xato kiritdingiz')
else:
for i in range(a,b+1):
print(i, end=':')
input()
#49-dars 2-topshiriq
#2.a va b sonlar berilgan. Agar a < b bо‘lsa, a dan b gacha #bо‘lgan sonlarni о‘sish tartibida, aks holda kamayish #tartibida chiqaring.
a=int(input('a='))
b=int(input('b='))
if afor i in range(b,a-1,-1):
print(i, end=':')
if a>=b:
for i in range(a,b-1,-1):
print(i, end=':')
input()
#49-dars 3-topshiriq
#3.1 dan 10 gacha bо‘lgan natural sonlar kvadratlarini #chiqaruvchi dastur tuzing.
for i in range(1,11):
print(i,'ni kvadrati',i*i)
input()
#49-dars 4-topshiriq
#4.1 dan 10 gacha bо‘lgan natural sonlar yig‘indisini #chiqaruvchi dastur tuzing.
i=1;s=0
for i in range(11):
s=s+i
print('s=',s)
#51-dars. AMALIY MASHG‘ULOT
#51-dars 2-mashq
#2.1 dan n gacha bо‘lgan natural sonlar kvadratlari yig‘indisini #aniqlovchi dastur yozing.
n=int(input('n='))
s=0
for i in range(1,n+1):
k=i*i
s=s+k
print(s)
input()
#51-dars 3-mashq
#3.n>=2 shartni qanoatlantiruvchi n soni berilgan. Ushbu ifodani #hisoblovchi dastur tuzing. d=1*2+2*3...+(n–1)*n #print('n>=2 shartni bajaruvchi sonni kiriting') d=0
n=int(input('n='))
for n in range(2,n+1):
k=(n-1)*n
d=d+k
print(d)
input()
#51-dars 4-mashq
#4.Bir nechta son berilgan. Ular orasida qancha 2 soni bor ekanligini #aniqlovchi dastur tuzing.
print('Nechta son kiritasiz?')
a=int(input('a='))
s=0
for i in range(a):
print('sonni kiriting')
n=int(input('n='))
if n==2:
s=s+1
print(s,'ta 2 raqami mavjud')
input()
#51-dars 5-mashq
#5.S=11+13+15+…+49 yig‘indini hisoblash dasturini tuzing.
s=0
for i in range(11,49,2):
s=s+i
print('s=',s)
input()
#51-dars 6-mashq. Va nihoyat juda sodda holda chidi
#6. n ta uchburchakni ekranga chiqaruvchi dastur tuzing. n –1 #dan 9 gacha bо‘lgan natural sonlarni qabul qiladi.
n=int(input('n='))
for i in range(1,n+1):
print(' * ')
print(' * * ')
print(' * * * ')
print('* * * *')1>
Do'stlaringiz bilan baham: |