Menu
Coddy logo textTech
flag Ar iconالعربيةdown icon

عرض جميع المصاريف

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

challenge icon

التحدي

سهل

تعامل مع خيار عرض جميع المصاريف (2).

إذا كانت قائمة المصاريف فارغة، قم بطباعة:

No expenses recorded yet.

خلاف ذلك، قم بطباعة القائمة بالتنسيق التالي:

Your expenses:
1. 23.1
2. 35.5
3. 99.99
4. 15.2

بافتراض أن المصاريف التي تم إدخالها مسبقاً كانت 23.1، و 35.5، و 99.99 و 15.2. (بهذا الترتيب!)

جرّب بنفسك

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")

# Initialize an empty list to store expenses
expenses = []

while True:
    # Get user choice
    choice = input()
    
    if choice == "1":
        # Add a new expense
        amount = float(input())
        expenses.append(amount)
        print("Expense added successfully!")

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

جميع دروس Fundamentals

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