Kortej elementlariga murojat
Kortej elementlariga for va while takrorlash operatorlari orqali murojaat quyidagicha
amalga oshiriladi:
user=("Erkin",30,True)
i=0
print("for sikli yordamida")
for u in user:
print(u)
print("while sikli yordamida")
while i
print(user[i])
i+=1
Kortej elementini mavjudlikka tekshirish
Kortejda biror elementning mavjudligini xuddi ro’yxatlardagi kabi in operatoridan
foydalanib amalga oshiriladi:
user=("Erkin",30,True)
if "Erkin" in user:
print("Foydalanuvchi ismi Erkin")
Murakkab kortejlar
davlatlar=(
("O'zbekiston",33.8,
(("Toshkent",2.65,
("Samarqand",1.1),
("Urganch",0.223)
),
("Qozog'iston",17.5,
(("Nur Sultan",1.1),
("Olmaota",2.3))
))))
for davlat in davlatlar:
nomi,aholi_soni,shaharlar=davlat
print(nomi,'-',aholi_soni)
print("Katt shaharlari:")
for shahar in shaharlar:
print(shahar[0],'-',shahar[1])
2.Kortejlarga misollar
Masala. , , , , va
elementlardan iborat bo‘lgan “Talaba” kotreji hosil qilinsin va talabalar ro‘yxati tuzilsin. Hamda, ro‘yxatlar bilan ishlash metodlari va funksiyalaridan foydalanib kotrejlar ustida quyidagi amallar bajarilsin:
➢ Qo‘shish, o‘chirish, tahrirlash va boshqa amallar bajarilsin;
➢ Erkaklar soni eng ko‘p bo‘lgan kurs nomeri;
➢ Eng ko‘p tarqalgan erkak va ayollar ismlari;
➢ Yoshi va ismi bir xil bo‘lgan talaba qizlar familiyalarining alfavit tartibidagi
ro‘yxati;
➢ Ro‘yxat kurslarga ajratilsin.
def AddStudent():
global students
fam = input("Familiya: ")
ism = input("Ism: ")
sharif = input("Otasining ismi: ")
jins = input("Jinsi: ")
yosh = int(input("Yoshi: "))
kurs = int(input("Kursi: "))
new_student = (fam, ism, sharif, jins, yosh, kurs)
student.append(new_student)
def EditStudent():
global students
fam = input("Tahrirlamoqchi bo'lgan familyangizni tanlang: ") for item in students:
if fam.lower() == item[0].lower():
print("Enter the data of editing student")
item[0] = input("Familiya: ")
item[1] = input("Ism: ")
item[2] = input("Otasining ismi: ")
item[3] = input("Jinsi: ")
item[4] = int(input("Yoshi: "))
item[5] = int(input("Kursi: "))
break
def DeleStudent():
global students
fam = input("O'chirmoqchi bo'lgan familyangizni tanlang: ")
for item in students:
if fam.lower() == item[0].lower():
students.remove(item)
break
def PrintAll():
global students
for item in students:
Print(item)
def PrintMostMen():
pass
def PrintTheMostNames():
pass
def PrintEquallyNamesWomen():
pass
def PrintSeprateByCourseNumbers():
pass
def Print(student):
print("Familiyasi: ", student[0])
print("Ismi: ", student[1])
print("Sharifi: ", student[2])
print("Jinsi: ", student[3])
print("Yoshi: ", student[4])
print("Kursi: ", student[5])
while True:
print("Buyruqlar:")
print("1-Yangi talaba qo'shish")
print("2-Tahririlash")
print("3-O'chirish")
print("4-Oxirgi talabani chiqarish")
print("5-Erkaklar soni eng ko'p bo'lgan kurs nomeri")
print("6-Eng ko‘p tarqalgan erkak va ayollar ismlari")
print("7-Yoshi va ismi bir xil bo‘lgan talaba qizlar familiyalarining alfavit tartibidagi ro‘yxati")
print("8-Ro‘yxat kurslarga ajratilsin")
print("9-Talabalar ro'yxatini chop etish")
print("0-Chiqish")
command = int(input("Buyruq raqamini kiriting: "))
if command == 1:
AddStudent()
continue
if command == 2:
EditStudent()
continue
if command == 3:
DeleStudent()
continue
if command == 4:
PrintLastStudent()
continue
if command == 5:
PrintMostMen()
continue
if command == 6:
PrintTheMostNames()
continue
if command == 7:
PrintEquallyNamesWomen()
continue
if command == 8:
PrintSeprateByCourseNumbers()
continue
if command == 9:
Print()
continue
if command == 0:
break
Do'stlaringiz bilan baham: |