12-amaliy mashg‘ulot Qism dasturlar: funksiyalar va protseduralar. Reja
Download 23.44 Kb.
|
1 2
Bog'liq12amaliy
- Bu sahifa navigatsiya:
- Kiruvchi ma’lumot Chiquvchi ma’lumot
def chiziq(): print( ‘- ‘*n) n=int(input( ‘n= ‘)) chiziq() 4. ‘*’ belgisidan tomoni n ga teng kvadrat chizuvchi dastur tuzing. Protseduradan foydalaning.
def yulduz(): for i in range(1.n+1) print( ‘ * ‘n.end= “ ” “ +” “/n”) n=int(input( ‘n= ‘)) yulduz() 5. Berilgan n sonining bo‘luvchilarini bitta qatorda probel orqali ajratib chiqaruvchi dastur tuzing. Protseduradan foydalaning.
def son(): for i in range(1.n+1): if n% i==0: print( i.end= ‘ ‘) n=int(input( ‘n= ‘)) son() 6. Berilgan n sonini rim raqamlarida ifodalovchi dastur tuzing. Protseduradan foydalaning.
a=[(1000, ‘ M ‘),(900, ‘ CM’),(500, ‘ D ‘),(400, ‘ DC’),(100, ‘C’),(90, ‘XC ‘), (50, ‘L ‘),(40, ‘ XL ‘),(10, ‘ X’),(9, ‘IX ‘),(5, ‘ V’),(4, ‘ IV),(1, ‘ I ‘)] def rim(n): s= ‘ ‘ while n>0: for i,r in a: while n>=i: s+=r n-=I return s n=int(input( ‘n= ‘)) print(rim(n)) 7. Berilgan n soni xonalarining yig‘indisini hisoblash dasturini tuzing. Protseduradan foydalaning.
def son(n): s=0 while n>0: m=n%10 n=n//10 s+=m return s n=int(input( ‘n= ‘)) print(son(n)) 8. Sport musobaqasida sportchilarning chiqishlari hakamlar tomonidan ballik tizimda baholandi. Yakuniy ballni olish uchun eng yuqori va eng past ball chiqarib tashlandi va qolgan uchta ballning o‘rtacha arifmetik qiymati hisoblandi. 5 nafar hakam tomonidan berilgan eng yuqori va eng past ballni hamda sportchi olgan ballni chiqaradigan dastur tuzing. Funksiyadan foydalaning.
def sport(n): a=n[0] b=n[4] s=(int(n[1])+int(n[2])+int(n[3]))/3 Print(a+b) return s n=int(input( ‘n= ‘)) print(son(n)) 9. Berilgan n soni xonalari raqamlarining sonini chiqaruvchi dastur tuzing.
def raqam(n): s=0 while n>0: n=n//10 s+=1 return s n=int(input( ‘n= ‘)) print(son(n)) Download 23.44 Kb. Do'stlaringiz bilan baham: |
1 2
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling