Javob: 2 O‘rta geometrik qiymatlarini aniqlang


Download 87.97 Kb.
Sana22.04.2023
Hajmi87.97 Kb.
#1377261
Bog'liq
python Topshiriq1 yangi



1-Topshiriq
Aslamov Xislat 915-20

1. Ikkita musbat son berilgan, bu sonlarning o‘rta arifmetik va o‘rta geometrik qiymatlarini aniqlang


import math
n = int(input("son 1 = "))
m = int(input("son 2 = "))
print((n+m)/2)


Javob:



1.2 O‘rta geometrik qiymatlarini aniqlang
import math
n = int(input("son 1 = "))
m = int(input("son 2 = "))
print(math.sqrt(n*m))


Javob:


2. Kvadrat tenglamaning ildizlarini topuvchi dastur tuzing
from math import sqrt

a = float(input("a = "))


b = float(input("b = "))
c = float(input("c = "))
d = int(b ** 2 - 4 * a * c)
print(d)
if d > 0:
x1 = (-b - sqrt(d)) / 2 * a
x2 = (-b + sqrt(d)) / 2 * a

print(x1, x2)


if d == 0:
x1 = (-b - sqrt(d)) / 2 * a
print(x1)
if d < 0:
print("ildizga ega emas")


Javob:____5._Berilgan_raqamning_birinchi_va_oxirgi_raqamlari_yigindisini_chop_etadigan_dasturini_Python_yozing'>Javob:



3. Berilgan ikkita matndagi oxirgi harflarini almashtiruvchi dasturni yozing
Kiruvchi : ‘salon’ , ‘nom’
Chiquvchi: ‘salom’ , ‘non’
s, s1 = map(str, input().split())
s, s1 = s[:-1] + s1[-1], s1[:-1] + s[-1]
print(s, s1)


Javob:______10._Python_dasturida_berilgan_ro`yxatdagi_musbat_sonlarni_filtrlash_dasturini_tuzing'>Javob:

4. "To’plar: 12 ta qora 45 ta qizil” shu matndan sonlarni ajratuvchi dastur tuzing
s = input()
arr = []
i = 0
while i < len(s):
if s[i].isnumeric():
arr.append(int(s[i]))
j = 1
if i+j == len(s):
break
while s[i+j].isnumeric():
arr[-1] = arr[-1]*10+int(s[i+j])
j += 1
if i+j == len(s):
break
i += j
else:
i += 1
print(*arr)


Javob:



5. Berilgan raqamning birinchi va oxirgi raqamlari yig'indisini chop etadigan dasturini Python yozing
n = input("Son kiriting = ")
s = int(n[0]) + int(n[-1])
print(s)


Javob:





6. Kiritilgan sonning raqamlar yigindisini toping
son = input("son kiriting = ")
x = list(son)
print(x)
yigindi = 0
for i in range(len(x)):
yigindi += int(x[i])
print(yigindi)


Javob:





7. Ikki xonali 5 ga bo`linadigan va 4 ga bo`linmaydigan sonlarni topish uchun dastur tuzing
def ketma_ketlik():
for i in range(10,100):
if i%5==0 and i%4!=0:
print(i)
ketma_ketlik()


Javob:



8. Ikki xonali toq sonlarning yig`indisini topish uchun Python dasturini yozing

print(sum(range(11,100,2)))




Javob:





9. 1
22
333
4444
55555
Berilgan ketma ketlikni dasturini tuzing

n = int(input("chegarani kiriting = "))


for i in range(1,n+1):
print(str(i) * i)


Javob:





10. Python dasturida berilgan ro`yxatdagi musbat sonlarni filtrlash dasturini tuzing

a=[1,2,3,34,-58,-24,-33,47,21]


b=list(filter(lambda x: x>0, a))
print(b)


Javob:



11.Joriy sana va vaqtni chiqarish dasturini tuzing.

import time

vaqt = time.strftime("%H:%M:%S")
print("joriy vaqt = ", vaqt)


Javob:





12. Yil va oy kiritilgandan so`ng taqvimni chiqarish dasturini tuzing
import calendar

yil = int(input("yilni kiriting = "))


oy = int(input("oyni kiriting = "))
cr = calendar.TextCalendar(calendar.SUNDAY)
cr.prmonth(yil,oy)

Javob:

Download 87.97 Kb.

Do'stlaringiz bilan baham:




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