تتبع إنفاقك (أو عاداتك)
تعرف على كيفية تسجيل إدخال المنظمة في ملف.
سنغطي ما يلي...
سنغطي ما يلي...
دعونا بناء مشروع Python حقيقي: متتبع!
يمكنك استخدامه لتسجيل الإنفاق والعادات والتدريبات - أي شيء تريد الاحتفاظ بسجل له.
الخطوة 1: مسجل الإنفاق البسيط
while True:
    item = input("Enter an item (or 'done' to finish): ")
    if item == "done":
        break
    amount = input("How much did you spend on it? ")
    with open("expenses.txt", "a") as file:
        file.write(item + ": $" + amount + "\n")  # Concatenate the strings before writing
print("All expenses saved!")We’re asking the user for what they spent on and how much, and saving it to a file
 ...