6) “input” nomli fayldagi matnda nechta simmetrik so’z print(lugat)
borligini topuvchi dastur tuzing
n=input().split(); s=0; fil=open(“input”,”w”)
for i in n:
fil=open(“input”,”r”):
fil.close; fil=open(“input”,”r”); a=fil.read()
b=a.split()
for i in b:
if i==[::-1]:
s=s+1
print(s)
13) 2 ta lug’atning kalitlarga mos qiymatlarini yig’indisini
aniqlash dasturini tuzing.
from collection import Counter
d1 = {'a': 100, 'b': 200, 'c':300}
d2 = {'a': 300, 'b': 200, 'd':400}
d=Counter(d1)+Counter(d2)
print(d)
14) Bugundan boshlab keyingi n ta kunni chop etadigan
dastur tuzing?
import datetime
n = int(input("Enter the number of days: "))
today = datetime.date.today()
for i in range(n):
next_day = today + datetime.timedelta(days=i)
print(next_day)
26)Lug’atda ro’yxatni olib alifbo tartibida tartiblovchi f-ya tuzing.
meva=["anor","olma","behi","olcha"]
print(sorted(meva))
7) “input” nomli fayldagi tug’ilgan sanasi “dd/mm/yyyy”
Formatida kiritilgan ekranga shuni Yoshi chiqsin
from datetime import*
dat=datetime.now()
s=[]
a=input().split(‘/’)
file=open(‘input’,’w’)
for i in a:
file.write(i+’ ‘)
file=open(‘input’,’r’)
a=file.read()
a1=a.split()
for j in a1:
s.append(j)
print(dat.year-int(s[2]))
15) Lambda yordamida berilgan ro‘yxatdagi satrlarning
palindromlarni toppish dasturini f-ya yordamida tuzing?
def palindromlarni_topish(royxat):
palindromlar = list(filter(lambda x: x == x[::-1], royxat))
return palindromlar
satrlar = ['madam', 'arbob', 'level', 'python', 'aziza']
palindromlarni_topish(satrlar)
print("Palindromlar:", palindromlar)
Do'stlaringiz bilan baham: |