Mobil qurilmalarda Java dasturlash
Download 286.52 Kb.
|
4. Pythonда рўйҳатлар билан ишлаш
- Bu sahifa navigatsiya:
- Ro‘yxatlarning metodlari
- Ro‘yxatlar bilan ishlash funksiyalar
- Masala
- Masala kodi 1
- Masala kodi 2
- Masala kodi 3
- Masala kodi 4
- Masala kodi 5
- Vazifalar
Python dasturlash tili 4 – amaliyot Pythonda ro‘yxatlar bilan ishlash Amaliy matematika va kompyuter tahlili kafedrasi o’qituvchisi: Allaberdiyev B. Ro‘yxatlar
Ro‘yxatlarning metodlari
Ro‘yxatlar bilan ishlash funksiyalar
Masala
Masala kodi 1# Bo'sh ro'yxat yaratish phonenumbers = [] while True: print("Buyruqlar:") print("1-Yangi raqam qo'shish") print("2-Tahririlash") print("3-O'chirish") print("4-Oxirgi raqami chiqarish") print("5-Ro‘yxatlar qismlarga" + "ajratilsin: juft va toq o‘rindagilar") print("6-Raqamalar o‘sish va " + "kamiyish bo‘yicha tartiblansiz") print("7-Ro‘yxat tozalansin") print("8-Raqamalarni chop etish") 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 # Ikkinchi buyroq funksiyasiga murojat qilish if command == 2: EditNumber() continue # Uchunchi buyroq funksiyasiga murojat qilish if command == 3: DeleteNumber() continueMasala kodi 3# 4-buyroq funksiyasiga murojat qilish if command == 4: PrintLastNumber() continue # 5-buyroq funksiyasiga murojat qilish if command == 5: SeperateByOddAndPair() continue # 6-buyroq funksiyasiga murojat qilish if command == 6: Sort() continue # 7-buyroq funksiyasiga murojat qilish if command == 7: phonenumbers.clear() continue# 8-buyroq funksiyasiga if command == 8: for item in phonenumbers: print(item) continue # 0-buyroq funksiyasiga if command == 0: # Exit while break Masala kodi 4# Func adding new number def AddNumber(): # Calling talabalar for local global phonenumbers number = input("New number: ") # Add it to end of the phonenumbers' list phonenumbers.append(number) def EditNumber(): global phonenumbers # Input the numbers data for deleting number = input("Enter the number that you want to edit: ") # Finding the item in which the number for item in phonenumbers: if number.lower() == item[0].lower(): print("Enter the data of editing number") item[0] = input("New number: ") breaMasala kodi 5# Func: deleting the needed number def DeleteNumber(): global phonenumbers # Input the numbers data for deleting number = input("Enter the number that you want to delete: ") # Finding the item in which the number for item in phonenumbers: if number.lower() == item[0].lower(): phonenumbers.remove(item) break # Func: printing the last number def PrintLastnumber(): global phonenumbers # Get last number's data last_number = phonenumbers[-1] print("The last number: ") print(last_number)Vazifalar
def SeperateByOddAndPair(): pass def Sort(): pass Download 286.52 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2025
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling