54-dars 1-mashq 1. S = 0,5 + 1,5 + 2,5 +…+ 98,5 + 99,5 ifodani hisoblash dasturini tuzing.
s=0
i=0.5
while i<=100:
s=s+i
i+=1
print(s)
input()
54-dars 2-mashq 2. n natural sonining barcha bo‘luvchilarini chiqaruvchi dastur tuzing.
n=int(input('n='))
i=0
while i<=n+1:
i+=1
b=n/i
a=n//i
if a==b:
print(a)
input()
54-dars 3-misol 1-usul 3.Kiritilgan n soni qancha raqamdan iborat ekanligini aniqlovchi dastur tuzing (ko‘rsatma: n = n%10 ifoda n = 0 bo‘lguncha bajariladi).
n=int(input('n='))
a=len(str(n))
print(n,'soni ',a,' ta raqamdan iborat' )
input()
54-dars 4-mashq 4.Kiritilgan n soni raqamlari yig‘indisini hisoblovchi dastur tuzing.
a=input('a=')
n=len(a)
a=int(a)
s=0
for i in range(1,n+1):
b=a//(10**(i-1))%10
s+=b
print(s)
input()
54-dars 5-mashq 5.Kiritilgan n soni juft raqamlari sonini hisoblovchi dastur tuzing.
a = input('Sonni kiriting: ')
n = len(a)
a=int(a)
j = 0
for i in range(1,n+1):
b=a//(10**(i-1))%10
if b%2==0:
j+=1
print(j,'ta juft raqam bor')
input()
54-dars 6-mashq 6.n natural soni berilgan. 1 dan n gacha bo‘lgan natural sonlar ichida oxirgi raqami 3 gа karrali sonlarni chiqaruvchi dastur tuzing.
a = int(input('Sonni kiriting: '))
for i in range(1,a):
b=i%10
if b%3==0 and b!=0:
print(i)
55-dars 1-masala 1. Qo‘shish, ayirish, ko‘paytirish va bo‘lish amallaridan iborat sodda kalkulyator dasturini tuzing.
a=int(input('a ni kiriting, a='))
b=int(input('b ni kiriting, b='))
print('amalni kiriting va enterni bosing')
amal=input('+ - * /')
if amal=='+':
c=a+b
elif amal=='-':
c=a-b
elif amal=='*':
c=a*b
elif amal=='/':
c=a/b
else:
c=(' AMAL XATO!')
print('natija c=',c)
Foydalanuvchi tomonidan kiritilgan sonlar yig‘indisini hisoblash dasturini tuzing. Agar manfiy son kiritilsa, sikl o‘z ishini to‘xtatishi lozim.
while True:
a=int(input('a='))
b=int(input('b='))
if a>=0 and b>=0:
s=a+b
print('s=',s)
else:
break
56-dars 1-misol n va k butun musbat sonlar berilgan. n va k qatnashgan ushbu ifodani hisoblang. n!/k!(n-k)! Funksiyadan foydalaning.
def factorial(n):
if n==0:
return 1
else:
natija=n*factorial(n-1)
return natija
n=int(input('n= '))
k=int(input('k= '))
m=n-k
N=factorial(n)
K=factorial(k)
M=factorial(m)
S=N/(K*M)
print('natija=',S)
56-dars 2-masala n natural son berilgan. Kvadrati n dan kichik bo‘lgan barcha natural sonlarni chiqaruvchi dastur tuzing.
from math import*
i=1
n=int(input('n= '))
54
m=int((sqrt(n)))
while i<=m:
print(i)
i+=1
56-dars 3-masala 3.Bir birlik uzunlik ‘-’ ga teng. Berilgan n uzunlikdagi ‘-’ belgidan iborat chiziq chizuvchi dastur tuzing. Protseduradan foydalaning.
print('nechta _ belgisi qo`yilsin? a=')
a=int(input())
print('_'*a)