1. n ni necha xonali sonligini topish n=int
Download 16.19 Kb.
|
masalalar
While 1.n ni necha xonali sonligini topish n=int(input("n= ")) s=0 while n>0: n=n//10 s+=1 print(s) 2.n sonning raqamlari yig’indisini toppish n=int(input("n= ")) s=0 while n>0: m=n%10; n=n//10 s=s+m print(s) 3.n sonida nechta juft raqam borligini aniqlovchi dastur n=int(input("n= ")) s=0 while n>0: m=n%10; n=n//10 if m%2==0: s+=1 print(s) 4.n natural soni berilgan.1 dan n gacha bo’lgan sonlar ichidan oxirgi raqami 3 ga karrali sonlarni chiqaruvchi dastur n=int(input("n= ")) i=1 while i if (i%10)%3==0: print(i,end=",") Break 1.Karra jadval mashqini bajaruvchi dastur(savol javob) karra=5 for i in range(1,11): print(karra,"x",i,"=?") javob=input() if javob=="bilmayman": break natija=karra*i if int(javob)==natija: print("barakalla") else: print("javobingiz xato to'g'ri javob",natija) print("Mashq tugadi") 2.Sodda kalkulyator yarating (+,-,*,/ - amallarini bajarsin) a=int(input("a= ")) amal=input("Bajarish amalini kiriting ") b=int(input("b= ")) if amal=="+": print(a+b) elif amal=="-": print(a-b) elif amal=="*": print(a*b) elif amal=="/": print(a/b) else: print("Bunday amal mavjud emas") 3.Kiritgan sonlarni yig’indisini ekranga chiqaruvchi dastur(manfiy son kiritilsa dastur to’xtaxdi) a=int(input("Nechta son kiritmoqchisiz? ")) s=0 for i in range(a): k=int(input()) if k<0: break else: s=s+k print(s) 4.Salom so’zini 5 marta ekranga chiqaruvchi dastur tuzing(break operatori yordamida) a=0 while a>=0: if a==5: break a+=1 print("Salom") Funksiya def funksiya_nomi(parametrlari): buyruqlar_bloki – funksiyaning umumiy tuzilishi 1.Kvadrat yuzini hisoblovchi dastur def yuza(a): yuzi=a**2 return yuzi a=int(input("a ni kirit= ")) print(yuza(a)) 2.1 dan a gacha sonlar yig’indisi def yigindi(a): s=0 for i in range(1,a+1): s=s+i return s a=int(input("a ni kirit= ")) print(yigindi(a)) 3.n faktorialni hisoblovchi dastur def faktorial(n): s=1 for i in range(1,n+1): s=s*i return s n=int(input("n= ")) print(faktorial(n)) Download 16.19 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2025
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling