N butun son berilganu ning darajasi ekanligini aniqlang


) Berilgan songa teskari sonni aniqlash dasturini


Download 134.94 Kb.
bet4/10
Sana22.06.2023
Hajmi134.94 Kb.
#1647477
1   2   3   4   5   6   7   8   9   10
Bog'liq
dasturlash shpargalka

22) Berilgan songa teskari sonni aniqlash dasturini
try… except dan foydalanib tuzing.
try:
son = int(input("Sonni kiriting: "))
print("Teskari son:","1/"+str(son))
except ValueError:
print("Noto'g'ri son kiritdingiz.")

21) Matndagi eng uzun so’zni topuvchi dasturni funksiya
yordamida tuzing
t=input(“matn kirit”)
def uzun(t):
words=t.split()
eng_uzun_soz=””
for i in words:
if len(i)>len(eng_uzun_soz):
eng_uzun_soz=i
return eng_uzun_soz
eng_uzun_soz=uzun(t)
print(“eng uzun so’z:”,eng_uzun_soz)

25)Ro’yxatda 2 va undan ortiq takrorlangan ro’yat elementlari va


indekslarini ekranga chop etish dasturini tuzing
n=tuple(input().split());p=''
n1=list(n)
n2=set(n)
n3=list(n2)
for i in range(len(n3)):
x=n1.count(n3[i])
if x>=2:
p+=n3[i]+'==>'
for j in range(n1.count(n3[i])):
m=n1.index(n3[i])
del n1[m]
n1.insert(m,'*')
p+=str(m)+','
print(p)

11) Ismlar kortejida 2 va undan ortiq ism qatnashganlar aniqlansin


va qaysi indeksda ekanligi chiqarilsin
n=tuple(input().split());p=''
n1=list(n)
n2=set(n)
n3=list(n2)
for i in range(len(n3)):
x=n1.count(n3[i])
if x>=2:
p+=n3[i]+'==>'
for j in range(n1.count(n3[i])):
m=n1.index(n3[i])
del n1[m]
n1.insert(m,'*')
p+=str(m)+','
print(p)


18) Uchburchak nomli sinf yarating, unda uchburchak
Yuzasi va peremetri topuvchi metodlar mavjud bo’lsin
class Uchburchak:
def __init__(self,a,b,c):
self.a=a
self.b=b
self.c=c
def perimetr(self):
return self.a+self.b+self.c
def yuza(self):
s=self.perimetr()/2
return (s*(s-self.a)*(s-self.b)*(s-self.c)**0.5)
t=Uchburchak(3,4,5)
print(t.perimetr());
print(t.yuza())


Download 134.94 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10




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