Mobil qurilmalarda Java dasturlash
Download 285.49 Kb.
|
7. Pythonда тўпламлар билан ишлаш.
- Bu sahifa navigatsiya:
- Masala kodi 1
- Masala kodi 2
- Masala kodi 3
- Masala kodi 4
Python dasturlash tili7 – amaliyot Pythonda to‘plamlar bilan ishlash. Amaliy matematika va kompyuter tahlili kafedrasi o’qituvchisi: Allaberdiyev B. To‘plamlar
talabalar = {"Bobur", "Zafar", "Alisher"} print(talabalar) # {'Bobur', 'Zafar', 'Alisher'}
son = {"1", "1", "2","2", "2"} print(son) # {'2', '1'} frozenset to‘plam.frozenset - o’zgartirib bo’lmaydigan to’plamlarni yaratish uchun ishlatiladi. Ushbu turdagi to’plamga yangi element qo’shish, o’chirish yoki element qiymatini o’zgartirishga ruxsat berilmaydi. frozenset turidagi to’plam odatda ro’yхat, kortej yoki oddiy to’plam (set) orqali hosil qilinadi:famil = {"Axmad", "Sardor", "Ikrom"} fam = frozenset(famil) print(fam) # frozenset({'Sardor', 'Ikrom', 'Axmad'}) frozenset uchun funksiyalar.frozenset turidagi to’plamlar ustuda quyidagi amallarni bajarish mumkin:
Masala
Masala kodi 1# Bo'sh ro'yxat yaratish numbers1 = set() numbers2 = set() fnumbers = frozenset() while True: print("Buyruqlar:") print("1-Yangi raqam qo'shish") print("2-O'chirish") print("3-Birinchi to‘plam ikkinchisiga kiradimi") print("4-frozenset to‘plamiga yuqoridagi to‘plam o‘tkazilsin") print("5-x element mavjud bormi tekshirilsin") print("6-Ikkita to‘plam birlashmasi hosil qilinsin") print("7-Ikkita to‘plam ayirmasi hosil qilinsin") print("8-Ikkita to‘plam solishtirilsin") print("0-Chiqish")Masala kodi 2# Buyruqni kiritish command = int(input("Buyruq raqamini kiriting: ")) # Birinchi buyroq funksiyasiga murojat qilish if command == 1: AddNumber() # Keyingi if shartlarni qaramaslik uchun continue # Uchunchi buyroq funksiyasiga murojat qilish if command == 2: DeleteNumber() continue # 4-buyroq funksiyasiga murojat qilish if command == 3: print(numbers1.issuperset(numbers2)) print(numbers2.issuperset(numbers1)) continueMasala kodi 3if command == 4: ToFrozenSet() continue if command == 5: X_in_Set() continue if command == 6: union = numbers1.union(numbers2) print(union) continue if command == 7: intersection = numbers1.intersection(numbers2) print(intersection) continueif command == 8: diff = numbers1. difference(numbers2) continue if command == 0: break Masala kodi 4# Func adding new number def AddNumber(): # Calling talabalar for local global numbers1 global numbers2 pass # Func: deleting the needed number def DeleteNumber(): global numbers1 global numbers2 # Input the numbers data for deleting pass def ToFrozenSet() global fnumbers pass def X_in_Set() passVazifalar.
def AddNumber(): global numbers1 global numbers2 pass def DeleteNumber(): global numbers1 global numbers2 # Input the numbers data for deleting pass def ToFrozenSet() global fnumbers pass def X_in_Set() pass Download 285.49 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling