Menu
CoddyTech

إضافة نفقة

جزء من قسم الأساسيات في رحلة Python على Coddy. الدرس 70 من 77.

challenge icon

التحدي

سهل

تعامل مع الخيار الذي يضيف فيه المستخدم نفقة (1).

  1. أنشئ في بداية البرنامج قائمة expenses فارغة
  2. عندما يختار المستخدم 1 كخيار، اطلب إدخالًا آخر من المستخدم، من النوع float، وأضف قيمته إلى قائمة expenses.
  3. بعد الإضافة، اطبع:
Expense added successfully!

جرّب بنفسك

print("Welcome to the Daily Expense Tracker!")

# Display menu once
print("\nMenu:")
print("1. Add a new expense")
print("2. View all expenses")
print("3. Calculate total and average expense")
print("4. Clear all expenses")
print("5. Exit")

while True:
    # Get user choice
    choice = input()

    if choice == "5":
        # Exit the program
        print("Exiting the Daily Expense Tracker. Goodbye!")
        break

جميع دروس الأساسيات

تدرّب بنفسك: مترجم Python عبر الإنترنت