Def top longest shortest word(words): longest word = ''
Download 0.54 Mb. Pdf ko'rish
|
Dedline1
def top_longest_shortest_word(words): longest_word = '' shortest_word = words[0] for word in words: if len(word) > len(longest_word): longest_word = word if len(word) < len(shortest_word): shortest_word = word return longest_word, shortest_word word_list = ['qizil', 'sariq', 'yashil', 'oq', 'qora', 'kok', 'pushti', 'suv'] longest, shortest = top_longest_shortest_word(word_list) print("Eng uzun so'z:", longest) print("Eng qisqa so'z:", shortest) 2 def calculate_character_frequencies(text): frequencies = {} for char in text: if char in frequencies: frequencies[char] += 1 else: frequencies[char] = 1 return frequencies text = input("Matnni kiriting: ") character_frequencies = calculate_character_frequencies(text) print("Belgilar chastotalari:") for char, frequency in character_frequencies.items(): print(f"{char}: {frequency}") products = { 'olma': 10000, 'banan': 5000, 'nok': 8000, 'shaftoli': 12000, 'uzum': 15000 } cart = {} while True: print("Mavjud mahsulotlar ro'yxati:") for product, price in products.items(): print(f"{product}: {price} so'm") choice = input("Savatga narsa qo'shish uchun mahsulot nomini kiriting (to'xtatish uchun 'stop' deb yozing): ") if choice == 'stop': break if choice in products: quantity = int(input(f"{choice} ni qancha miqdorda sotib olmoqchisiz? ")) if choice in cart: cart[choice] += quantity else: cart[choice] = quantity print(f"{choice} {quantity} ta savatga qo'shildi.") else: print("Kechirasiz, mavjud emas.") total_cost = 0 print("Savatdagi mahsulotlar:") for product, quantity in cart.items(): price = products[product] * quantity total_cost += price print(f"{product}: {quantity} ta, narxi: {price} so'm") discount_rate = 0.1 # 10% chegirma discounted_cost = total_cost - (total_cost * discount_rate) print(f"Umumiy xarajatlar: {total_cost} so'm") print(f"Chegirma miqdori: {total_cost * discount_rate} so'm") print(f"To'lov miqdori (chegirma bilan): {discounted_cost} so'm") Download 0.54 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling