2. Berilgan a butun son noldan farqli


Download 228.17 Kb.
Sana29.04.2023
Hajmi228.17 Kb.
#1401734
Bog'liq
9-SINF IF ELIF


1. Ikkita a va b son berilgan. Agar b son a sondan kichik bo‘lsa, u holda b ni nol bilan almashtiruvchi, aks holda b ni o‘zgarishsiz qoldiruvchi dastur tuzing.
a = int(input())
b = int(input())
if (a > b):
b = 0
print(b)
2. Berilgan a butun son noldan farqli b butun songa qoldiqsiz bo‘linishi yoki bo‘linmasligini aniqlovchi dastur tuzing.
a = int(input())
b = int(input())
if (a % b) == 0:
print(a+b)
else:
print(a*b)
3. Berilgan a butun son noldan farqli b butun songa qoldiqsiz bo‘linsa, bu ikkala sonning yig‘indisini, aks holda k‘poaytmasini topish dasturini tuzing.

a = int(input())


b = int(input())
if (a % b) == 0:
print(a+b)
else:
print(a*b)
4. Uchta a, b va c son berilgan. Agar a2 – b2 = c2 shart bajarilsa, ularning ko‘paytmasini, aks holda yig‘indisini hisoblovchi dastur tuzing.
a = int(input())
b = int(input())
c = int(input())
if (a**2+b**2) == c**2:
print(a*b*c)
else:
print(a+b+c)
5. Butun son berilgan. Agar u musbat bo‘lsa, unga 1 sonini qo‘shish, aks holda o‘zini chiqarish dasturini tuzing.
a = int(input())
if a > 0:
a = a+1
print(a)
6. Kiritilgan butun son musbat bo‘lsa, uning 10 ga ko‘paytmasini, aks holda o‘zini chiqaruvchi dastur tuzing.
a = int(input())
if a > 0:
a = a*10
print(a)

47-DARS




  1. Ikki xonali sonning raqamlari toq ekanligini aniqlovchi dastur tuzing.

a = input()
a1 = int(a[0])
a2 = int(a[1])
if (a1 % 2) != 0:
if (a2 % 2) != 0:
print('Raqamlari toq')
else:
print('Raqamlari toq emas')
else:
print('Raqamlari toq emas')

a=int(input('bi='))


b=a//10
i=a%10
if b%2!=0 and i%2!=0:
print('raqamlar toq',b,':',i)
else:
print(' raqamlar toq emas',b,':',i)



  1. Uch xonali sonda bir xil raqamlar mavjud ekanligini aniqlovch dastur tuzing.

print(‘Uch xonali son kiriting’)
a = input(‘a=’)
a1 = int(a[0])
a2 = int(a[1])
a3 = int(a[2])
if a1 == a2:
print('Bir xil raqamlari mavjud')
elif a1 == a3:
print('Bir xil raqamlari mavjud')
elif a2 == a3:
print('Bir xil raqamlari mavjud')
else:
print('Bir xil raqamlari mavjud emas')

print('uch xonali son kriting')


a = int(input('a='))
b = a % 10
i = (a // 10) % 10
u = a // 100
print(b,i,u)
if b == i or i == u or b == u:
print('bir hil raqamlar mavjud')
else:
print('bir hil raqamlar mavjud emas')



  1. a va b sonlardan qasi birlari juft ekanligini aniqlovchi dastur tuzing.

a = int(input())
b = int(input())
if a%2 == 0:
c='juft'
else:
c='juft emas'
if b%2 == 0:
d='juft'
else:
d='juft emas'
print(a,c)
print(b,d)
a = int(input())
b = int(input())
if a % 2 == 0:
print('a son juft')
if b % 2 == 0:
print('b son juft')

  1. Uchta butun son kiritildi qaysi birlari juft ekanligini aniqlovchi dastur tuzing.

a = int(input())


b = int(input())
c = int(input())
if a % 2 == 0:
print('a son juft')
if b % 2 == 0:
print('b son juft')
if c % 2 == 0:
print('c son juft')

48-DARS


  1. Uchta a, b va c butun son berilgan. Ular orasidan musbatlari sonini topish

dasturini tuzing.
a = int(input('a='))
b = int(input('b='))
c = int(input('c='))
i = 0
if a > 0:
i+=1
if b > 0:
i += 1
if c > 0:
i += 1
if i == 0:
print('Barcha sonlar manfiy')
else:
print(i,'ta son musbat')

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
else:
man += 1
if b > 0:
mus += 1
else:
man += 1
if c > 0:
mus += 1
else:
man += 1
print('musbat sonlar', mus)
print('manfiy sonlar', man)



  1. 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)

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:


print('a**2=', a**2)
if b > 0:
print('b**2=', b**2)
if c > 0:
print('c**2=', c**2)



  1. Kvadrat tenglamani yechish dasturini tuzing.

from math import*
a = int(input('a='))
b = int(input('b='))
c = int(input('c='))
d = b**2-4*a*c
if d > 0:
x1 = (-b+sqrt(d))/2*a
x2 = (-b-sqrt(d))/2*a
print(x1, x2)
elif d == 0:
x = -b/2*a
print(x)
else:
print('Tenglama echimga emas')
6. Hafta raqami 1–7 oraliqda kiritilganda, hafta kunini ekranga chiqaruvchi dastur
tuzing.
a = int(input('a='))
if a == 1:
print('Dushanba')
elif a == 2:
print('Seshanba')
elif a == 3:
print('Chorshanba')
elif a == 4:
print('Payshanba')
elif a == 5:
print('Juma')
elif a == 6:
print('Shanba')
elif a == 7:
print('Yakshanba')
else:
print("Bunday hafta kuni yo'q")

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='))
s = 0
if a > 0 and b > 0:
if (a+b) > 100:
s = a/b
else:
s = a*b
print(s)

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(1)
elif b > a:
print(2)
else:
print(0)
49-50 darslar
1. a va b sonlar berilgan. a dan b gacha bо‘lgan barcha sonlarni chiqaruvchi dastur
tuzing. Bu yerda a <= b.
a = int(input('a='))
b = int(input('b='))
for a in range(b):
print(a)

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 a < b:
for a in range(b):
print(a)
else:
for i in range(a, b, -1):
print(i)

3.1 dan 10 gacha bо‘lgan natural sonlar kvadratlarini chiqaruvchi dastur tuzing.


for i in range(1, 10):
print(i**2)



  1. 1 dan 10 gacha bо‘lgan natural sonlar yig‘indisini chiqaruvchi dastur tuzing.

s = 0
for i in range(1, 10):
s += i
print(s)

51-dars amaliy mashg’ulot



  1. 1 dan n gacha bо‘lgan natural sonlar kvadratlari yig‘indisini aniqlovchi dastur yozing.

n = int(input(‘n=’))
for i in range(1, n):
print(i**2)

3. n>=2 shartni qanoatlantiruvchi n soni berilgan. Ushbu ifodani hisoblovchi dastur


tuzing. d=1*2+2*3+...+(n–1)*n
n = int(input('n>=2 n='))
s = 0
for i in range(2, n):
s = s+(i-1)*i
print(s)
4. Bir nechta son berilgan. Ular orasida qancha 2 soni bor ekanligini aniqlovchi dastur
tuzing.
n = int(input('Nechta son kiritasiz: '))
s = 0
for i in range(n):
a = int(input())
if a == 2:
s += 1
print(n,'ta sonlar orasida',s,'ta 2 raqami bor')



  1. S=11+13+15+…+49 yig‘indini hisoblash dasturini tuzing.

s = 0
for i in range(11,50):
s += i
print(s)



  1. 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(n):
print(" *")
print(" * * ")
print(" * * *")
print("* * * *")
52-dars

  1. Butun son kiritilgan vaqtda sondan avval va keyin keluvchi sonni chiqaruvchi dastur

tuzing. Dastur natijasi quyidagicha bo‘lishi lozim.
n = int(input('n='))
print(n-1,n,n+1)



  1. Natural son berilgan. Shu son oxirgi raqamini topish dasturini tuzing.

n = int(input('n='))
print(n%10)

3. Sutkaning n sekundi berilgan. Sutka boshlanganidan beri qancha soat (h), minut


(min) va sekund (s) o‘tganini aniqlash dasturini tuzing.
masalan, n = 13257 = 3*3600 + 40*60 + 57; h = 3 va min = 40.
n = int(input('n='))
h = n//3600
m = (n%3600)//60
s = ((n%3600)%60)
print(h,'soat',m,'minut',s,'sekund')

4. Mahsulotning narxi s so‘m. Ushbu mahsulotdan n ta sotib olish uchun qancha so‘m


sarflash kerak?
n = int(input('n='))
s = int(input())
print(n*s)

5. Musbat butun son berilgan. Ushbu sonning o‘nliklar xonasidagi raqamini aniqlash


dasturini tuzing.
print(int(input('n='))%100//10)

6. Ismingizni kiritganda quyidagi xabarni chiqaruvchi dasturni tuzing. Dastur tuzishda


print() operatorining end() usulidan foydalaning.
Lola Xush kelibsiz, Lola!
n = input()
print("Xush kelibsiz,",n, end='!')

53-dars


  1. 0 dan 20 gacha bo‘lgan juft sonlarni ekranga chiqaruvchi dastur tuzing.

i = 0
while i < 20:
print(i+2)
i += 2



  1. n va k butun manfiy bo‘lmagan sonlar berilgan. n va k qatnashgan ushbu ifodani hisoblang.

n = int(input())
k = int(input())
i = 1
p = 1
while i < n:
p *= i
i += 1
nfak = p
i = 1
p = 1
while i < k:
p *= i
i += 1
kfak = p
i = 1
p = 1
while i < (n - k):
p *= i
i += 1
nkfak = p
print(nfak/kfak * nkfak)



  1. a va b natural sonlar berilgan. a dan b gacha bо‘lgan sonlar orasidan faqat juftlarini chiqaruvchi dastur tuzing. Bu yerda a <= b.

a = int(input())
b = int(input())
while a <= b:
if a % 2 == 0:
print(a)
a += 1

4. n natural soni berilgan. Kvadrati n dan kichik bo‘lgan barcha natural sonlarni


chiqaruvchi dastur tuzing.
n = int(input())
i = 1
while i**2 < n:
print(i)
i += 1
54-dars

  1. S = 0,5 + 1,5 + 2,5 +…+ 98,5 + 99,5 ifodani hisoblash dasturini tuzing.

i = 0.5
s = 0
while i < 100:
s += i
i += 1
print(s)



  1. n natural sonining barcha bo‘luvchilarini chiqaruvchi dastur tuzing.

n = int(input())
i = 1
while i <= n:
if n % i == 0:
print(i)
i += 1



  1. Kiritilgan n soni qancha raqamdan iborat ekanligini aniqlovchi dastur tuzing (ko‘rsatma: n = n//10 ifoda n = 0 bo ‘lguncha bajariladi).

n = int(input())
s = 0
while n != 0:
n = n // 10
s += 1
print(s)



  1. Kiritilgan n soni raqamlari yig‘indisini hisoblovchi dastur tuzing.

n = input()
s = 0
for i in range(len(n)):
s = s + int(n[i])
print(s)



  1. Kiritilgan n soni juft raqamlari sonini hisoblovchi dastur tuzing.

n = input()
print(len(n)//2)

6. n natural soni berilgan. 1 dan n gacha bo‘lgan natural sonlar ichida oxirgi raqami 3 gа


karrali sonlarni chiqaruvchi dastur tuzing.
print("Son kiriting.")
n = int(input('n='))
i = 1
while i <= n:
if (i % 10) % 3 == 0:
print(i)
i += 1

55-dars
1. Qo‘shish, ayirish, ko‘paytirish va bo‘lish amallaridan iborat sodda kalkulyator


dasturini tuzing.

2. Foydalanuvchi tomonidan kiritilgan sonlar yig‘indisini hisoblash dasturini tuzing.


Agar manfiy son kiritilsa, sikl o‘z ishini to‘xtatishi lozim.
print("Nechta son kiritasiz?")
n = int(input('n='))
s, k = 0, 0
for i in range(n):
a = int(input(f"{i+1}-son kiriting"))
if a < 0:
print('Siz manfiy son kiritingiz.')
break
s += a
k += 1
print(f"{k} ta son yig'indisi", s)

  1. n va k butun musbat sonlar berilgan. n va k qatnashgan ushbu ifodani hisoblang.


Funksiyadan foydalaning.
def factor(n):
if n==0:
return 1
else:
res= n*factor(n-1)
return res
n = int(input('n sonini kiriting: '))
k = int(input('k sonini kiriting: '))
print(factor(n)/factor(k)*factor(n-k))



  1. n natural son berilgan. Kvadrati n dan kichik bo‘lgan barcha natural sonlarni

chiqaruvchi dastur tuzing.
def kvadrat(n):
i = 1
while i <= n:
if i*i < n:
print(i)
i += 1
n = int(input('n sonini kiriting: '))
print(kvadrat(n))



  1. Bir birlik uzunlik ‘-’ ga teng. Berilgan n uzunlikdagi ‘-’ belgidan iborat chiziq chizuvchi

dastur tuzing. Protseduradan foydalaning.
UY VAZIFASI

def chiziq():
n = int(input('n sonini kiriting: '))
print(n*"-")


59-60 dars

  1. n natural soni berilgan. S=1*5+2*6+3*7+…+n*(n+4) ifodani hisoblash dasturini

protsedura yordamida tuzing.
def summm():
n = int(input())
s = 0
for i in range(n):
s = s + n*(n+4)
print(s)

  1. a va b natural sonlari berilgan. a va b sonlaridan kattasini topish funksiyasini tuzing.

Funksiyadan foydalanib, a, b va c sonlari ichidan kattasini topish dasturini tuzing.
def max(a,b):
if a > b:
retrun a
else:
retrun b
def max3(a,b,c):
retrun max(max(a,b),c)

a = int(input())


b = int(input())
c = int(input())
print(max3(a,b,c))
Download 228.17 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling