############################################################
# for-loop mechanism, range() objects
############################################################


print()
callout = ""
for count in range(1, 10):
    word = "duck"
    if count % 3 == 0:
        word = "GOOSE!"
    callout += word + "-"
    print(count, callout)


# EXERCISE: Given callout, count and print the number of words in it.


########################################


# print()
#
# # set interest rate and calculate multiplier
# interest_rate = 0.05
# days_in_year = 365
# daily_rate = interest_rate / days_in_year
# daily_multiplier = 1 + daily_rate
#
# # set initial balance
# balance = 1000
#
# # set monthly withdrawals and deposits
# withdrawal_date = 10
# withdrawal = 500
# deposit_date = 20
# deposit = 600
# end_date = 28
#
# # iterate over months
# for month in range(2, 13):
#
#     # iterate over dates in month
#     for date in range(1, end_date + 1):
#
#         # apply compound interest for one day
#         balance *= daily_multiplier
#
#         # apply withdrawal on correct date
#         if date == withdrawal_date:
#             balance -= withdrawal
#
#         # apply deposit on correct date
#         if date == deposit_date:
#             balance += deposit
#
#         # round to nearest cent
#         balance = round(balance, 2)
#
#     print("$" + str(balance))


# EXERCISE: Banks typically compound interest daily, but apply it to
# your account at the end of a month. Modify the code so that it tracks
# the compounded interest throughout each month, but waits until the end
# date to round it to the nearest cent and add it to the balance then.


############################################################
# solving problems by enumeration
############################################################


# solution 1: enumerate all 1000**3 possibilities
# print()
# total_tickets = 1000
# for alyssa in range(total_tickets + 1):
#     for ben in range(total_tickets + 1):
#         for cindy in range(total_tickets + 1):
#             if (
#                 ben == alyssa - 20
#                 and cindy == alyssa * 2
#                 and alyssa + ben + cindy == total_tickets
#             ):
#                 print("Alyssa:", alyssa, "tickets")
#                 print("Ben:   ", ben, "tickets")
#                 print("Cindy: ", cindy, "tickets")


# solution 2: directly relate ben and cindy to alyssa
# print()
# total_tickets = 1000
# for alyssa in range(total_tickets + 1):
#     ben = alyssa - 20
#     cindy = alyssa * 2
#     if ben < 0:
#         continue
#     if alyssa + ben + cindy == total_tickets:
#         print("Alyssa:", alyssa, "tickets")
#         print("Ben:   ", ben, "tickets")
#         print("Cindy: ", cindy, "tickets")
#         break


########################################


# solution 1: assign derek within inner loop, track best so far
# total_tickets = 1000
# max_derek = 0
# mda = 0
# mdb = 0
# mdc = 0
# for alyssa in range(total_tickets + 1):
#     ben = alyssa - 20
#     cindy = alyssa * 2
#     if ben < 0:
#         continue
#     for derek in range(ben, total_tickets + 1):
#         if alyssa + ben + cindy + derek == total_tickets:
#             if derek > max_derek:
#                 max_derek = derek
#                 mda = alyssa
#                 mdb = ben
#                 mdc = cindy
#                 break
#
# print()
# print("Derek could have sold up to", max_derek, "tickets, when:")
# print("    Alyssa sold", mda, "tickets")
# print("    Ben sold   ", mdb, "tickets")
# print("    Cindy sold ", mdc, "tickets")


# solution 2: assign derek in an outer loop, break on first solution
# total_tickets = 1000
# found_solution = False
# for derek in range(total_tickets, -1, -1):
#     for alyssa in range(total_tickets + 1):
#         ben = alyssa - 20
#         cindy = alyssa * 2
#         if ben < 0:
#             continue
#         if alyssa + ben + cindy + derek == total_tickets:
#             found_solution = True
#             break
#     if found_solution:
#         break
#
# print()
# print(f"Derek could have sold up to {derek} tickets, when:")
# print(f"    Alyssa sold {alyssa} tickets")
# print(f"    Ben sold    {ben} tickets")
# print(f"    Cindy sold  {cindy} tickets")


############################################################
# functions
############################################################


# print()
#
# # set interest rate and calculate multiplier
# interest_rate = 0.05
# days_in_year = 365
# daily_rate = interest_rate / days_in_year
# daily_multiplier = 1 + daily_rate
#
# # set initial balance
# balance = 1000
#
# # set monthly withdrawals and deposits
# withdrawal_date = 10
# withdrawal = 500
# deposit_date = 20
# deposit = 600
# # end_date = 28
#
# # iterate over months
# for month in range(2, 13):
#
#     # determine number of dates in month
#     if month == 2:
#         end_date = 28
#     elif month == 3:
#         end_date = 31
#     elif month == 4:
#         end_date = 30
#     elif month == 5:
#         end_date = 31
#     elif month == 6:
#         end_date = 30
#     elif month == 7:
#         end_date = 31
#     elif month == 8:
#         end_date = 31
#     elif month == 9:
#         end_date = 30
#     elif month == 10:
#         end_date = 31
#     elif month == 11:
#         end_date = 30
#     elif month == 12:
#         end_date = 31
#
#     # iterate over dates in month
#     for date in range(1, end_date + 1):
#         balance *= daily_multiplier
#         if date == withdrawal_date:
#             balance -= withdrawal
#         if date == deposit_date:
#             balance += deposit
#         balance = round(balance, 2)
#
#     print("$" + str(balance))


########################################


def get_num_dates(month):
    if month == 2:
        end_date = 28
    elif month == 3:
        end_date = 31
    elif month == 4:
        end_date = 30
    elif month == 5:
        end_date = 31
    elif month == 6:
        end_date = 30
    elif month == 7:
        end_date = 31
    elif month == 8:
        end_date = 31
    elif month == 9:
        end_date = 30
    elif month == 10:
        end_date = 31
    elif month == 11:
        end_date = 30
    elif month == 12:
        end_date = 31
    return end_date


# print()
#
# # set interest rate and calculate multiplier
# interest_rate = 0.05
# days_in_year = 365
# daily_rate = interest_rate / days_in_year
# daily_multiplier = 1 + daily_rate
#
# # set initial balance
# balance = 1000
#
# # set monthly withdrawals and deposits
# withdrawal_date = 10
# withdrawal = 500
# deposit_date = 20
# deposit = 600
#
# # iterate over months
# for month in range(2, 13):
#
#     # determine number of dates in month
#     end_date = get_num_dates(month)
#
#     # iterate over dates in month
#     for date in range(1, end_date + 1):
#         balance *= daily_multiplier
#         if date == withdrawal_date:
#             balance -= withdrawal
#         if date == deposit_date:
#             balance += deposit
#         balance = round(balance, 2)
#
#     print("$" + str(balance))


########################################


def track_balance():
    # set interest rate and calculate multiplier
    interest_rate = 0.05
    days_in_year = 365
    daily_rate = interest_rate / days_in_year
    daily_multiplier = 1 + daily_rate

    # set initial balance
    balance = 1000

    # set monthly withdrawals and deposits
    withdrawal_date = 10
    withdrawal = 500
    deposit_date = 20
    deposit = 600

    # track balance each month
    for month in range(2, 13):
        for date in range(1, get_num_dates(month) + 1):
            balance *= daily_multiplier
            if date == withdrawal_date:
                balance -= withdrawal
            if date == deposit_date:
                balance += deposit
            balance = round(balance, 2)

        print("$" + str(balance))


# print()
# track_balance()
