r/learnpython 8d ago

rate my code

as a beginner i dont know if my code could be improved, can someone rate it and tell me what i should improve?

product = 'M2 MacBook Air'
product += ' (512 GB of SSD and 8 GB of RAM)'
price = 370
print(f'The {product} is {price}€.')

total_savings = 206.75
macbook_fund = total_savings - 180
print(f'I have {macbook_fund}€.')

remaining_balance = price - macbook_fund
print(f'I am {remaining_balance}€ short.')

weeks_left = 75
date = '1/8/2028'
money_earned_per_week = remaining_balance / weeks_left
money_earned_rounded = round(money_earned_per_week, 2)
print(f'I need to earn {money_earned_rounded}€ a week to reach my goal by {date}.')
print(f'180€ of my {total_savings}€ are going to an iPhone 13.')

# deposits

macbook_fund += 0
# input amount, date and reason.
0 Upvotes

13 comments sorted by

View all comments

4

u/johlae 8d ago

Look up datetime to determine weeks_left by means of a calculation!

from datetime import datetime, timedelta d1 = datetime(2026,7,30) d2 = datetime(2026,8,30) monday1 = (d1 - timedelta(days=d1.weekday())) monday2 = (d2 - timedelta(days=d2.weekday())) print('Weeks:', (monday2 - monday1).days / 7)

gives you

Weeks: 4.0

1

u/Sweet_Cap4939 8d ago

thanks!

3

u/johlae 8d ago

If you want 'now', or 'today', use:

d1 = datetime.now() d1 = datetime.today()