5 – amaliyot
Pythonda murakkab ro‘yxatlar bilan ishlash
Amaliy matematika va kompyuter
tahlili kafedrasi o’qituvchisi: Allaberdiyev B.
Masala - Masala. , , , , va elementlardan iborat bo‘lgan “Talaba” murakkab ro‘yxati tuzilsin. Hamda, ro‘yxatlar bilan ishlash metodlari va funksiyalaridan foydalanib 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.
Masala kodi 1 # Bo'sh ro'yxat yaratish students = [] 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") Masala kodi 2 # Buyruqni kiritish command = int(input("Buyruq raqamini kiriting: ")) # Birinchi buyroq funksiyasiga murojat qilish if command == 1: AddStudent() # Keyingi if shartlarni qaramaslik uchun continue # Ikkinchi buyroq funksiyasiga murojat qilish if command == 2: EditStudent() continue if command == 3: DeleStudent() continue if command == 4: PrintLastStudent() continue
Ўзбекистон миллий университети, 2020
Masala kodi 3 # 5-buyroq funksiyasiga murojat qilish if command == 5: PrintMostMen() continue # 6-buyroq funksiyasiga murojat qilish if command == 6: PrintTheMostNames() continue # 7-buyroq funksiyasiga murojat qilish if command == 7: PrintEquallyNamesWomen() continue # 8-buyroq funksiyasiga murojat qilish if command == 8: PrintSeprateByCourseNumbers() continue
# 9-buyroq funksiyasiga if command == 9: Print() continue # 0-buyroq funksiyasiga if command == 0: # Exit while break
Ўзбекистон миллий университети, 2020
Masala kodi 4 # Func adding new student def AddStudent(): # Calling talabalar for local global students fam = input("Familiya: ") ism = input("Ism: ") sharif = input("Otasining ismi: ") jins = input("Jinsi: ") yosh = int(input("Yoshi: ")) kurs = int(input("Kursi: ")) # Create new student new_student = [fam, ism, sharif, jins, yosh, kurs] # Add it to end of the students' list student.append(new_student)
Ўзбекистон миллий университети, 2020
Masala kodi 5 # Func: editing the needed student's data def EditStudent(): global students # Input the students data for deleting fam = input("Enter the familiy that you want to delete: ") # Finding the item in which the student 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
Ўзбекистон миллий университети, 2020
Masala kodi 6 # Func: deleting the needed student def DeleStudent(): global students # Input the students data for deleting fam = input("Enter the familiy that you want to delete: ") # Finding the item in which the student for item in students: if fam.lower() == item[0].lower(): students.remove(item) break def PrintAll(): global students for item in students: Print(item)
Ўзбекистон миллий университети, 2020
Masala kodi 7 # Func: printing data of the men # who in the group which is the higest 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])
Ўзбекистон миллий университети, 2020
Vazifalar - Yuqoridagi masaladagi quyidagi asosiy funksiyalarning kodi yozilsin va testlar o‘tkazilsin:
- def PrintMostMen():
- def PrintTheMostNames():
- def PrintEquallyNamesWomen():
- def PrintSeprateByCourseNumbers():
Ўзбекистон миллий университети, 2020
Do'stlaringiz bilan baham: |