############################################################
# numeric objects and operations
############################################################


# order of operations
# print()
# print(7 + 8 * 2 - 12)
# print((7 + 8) * (2 - 12))
# print(10 / 2 ** 4)
# print(12e-3 + 1 * 0.1)  # scientific notation for floats


# division
# print()
# print(5 / 2)
# print(5 // 2)
# print(5 % 2)
# print(-6.5 // 3)
# print(-6.5 % 3)


# example: compound interest
# print()
# print(1000)                             # balance at end of January
# print(1000 * (1 + 0.05 / 365) ** 28)    # balance at end of February
# print(
#     1000
#     * (1 + 0.05 / 365) ** 28
#     * (1 + 0.05 / 365) ** 31
# )                                       # balance at end of March


# comparisons produce bools
# print()
# print(400 + 1 < 400)
# print(12 * 6 >= 8 * 9)
# print(5 == 5.0)
# print(5 == 5.00000001)
# print(1/6 + 1/6 + 1/6 + 1/6 + 1/6 + 1/6 == 1)  # false!


# additional operations
# print()
# print(round(-3.98765))
# print(round(-3.98765, 3))
# print(abs(3 * 3 - 16))
# print(min(1 * 5, 2 * 4, 3 * 3))
# print(max(1 * 5, 2 * 4, 3 * 3))


# pay attention to types, convert if needed
# print()
# print(9.0 - 3)
# print(int(9.0 - 3))
# print(int(9.6 - 3))
# print(float(9 - 3))


############################################################
# variables and branching
############################################################


# compound interest using variables
# print()
# interest_rate = 0.05
# days_in_year = 365

# balance = 1000
# print(balance)

# num_days = 28  # february
# balance = balance * (1 + interest_rate / days_in_year) ** num_days
# print(balance)

# num_days = 31  # march
# balance *= (1 + interest_rate / days_in_year) ** num_days
# print(balance)


# example: making deposits and withdrawals throughout february
# print()
# interest_rate = 0.05
# days_in_year = 365
# daily_rate = interest_rate / days_in_year
# daily_multiplier = 1 + daily_rate

# balance = 1000
# print(balance)

# withdrawal_date = 10
# withdrawal = 500
# deposit_date = 20
# deposit = 600
# end_date = 28

# balance *= daily_multiplier ** withdrawal_date
# balance -= withdrawal
# print(balance)

# balance *= daily_multiplier ** (deposit_date - withdrawal_date)
# balance += deposit
# print(balance)

# balance *= daily_multiplier ** (end_date - deposit_date)
# print(balance)

# exercise: what if interest rate changes to 3% after february 20?


# example: handling over-withdrawals
# print()
# overdraft_fee = 25
# daily_penalty = 2

# balance = 1000
# print(balance)

# withdrawal_date = 10
# withdrawal = 1200
# deposit_date = 20
# deposit = 600
# end_date = 28



# boolean operations
# print()
# print(not (3 + 4 < 5))
# print(3 + 4 >= 5)
# print()
# fast = True
# furious = False
# print(not (fast and furious))
# print((not fast) or (not furious))


# nested branching
# print()
# cavities = False
# brush_teeth = False

# original
# if not cavities:
#     if brush_teeth:
#         print("eat candy")
#     else:
#         print("eat fruit")
# else:
#     if brush_teeth:
#         print("eat bread")


############################################################
# strings
############################################################


# indexing and slicing
# donut = "whole-wheat"
# print()
# print(donut)
# print(donut[0], donut[1], donut[2])     # print() automatically adds spaces
# print(donut[-1], donut[-2], donut[-3])  # negative indices
# print()
# print(donut[2:5])               # slice notation [start:stop:step]
# print(donut[2:])
# print(donut[2:9:2])
# print(donut[:])
# print(donut[:5] + donut[5:])
# print()
# print(donut[-2:-5])             # slicing with negative indices
# print(donut[-2:-5:-1])
# print(donut[-7:7])              # combining positive and negatiave indexing


# concatenation and repetition
# former = "sam I am"
# latter = "I am sam"
# print()
# print(former + ", " + latter)
# print((former + ", ") * 3)      # exercise: remove the trailing comma
# print(((former + ", ") * 3)[:-2])

# left = "massachusetts"
# center = "institute"
# right = "technology"
# print()
# print(left[0:4] + " " + center[3::2] + " " + right[:-1])
# print(left[0:3] + center[-1] + right[1:4:2])


# converting between strs and other types
# print()
# cents = 12345
# cents_str = str(cents)
# dollars_str = cents_str[:3] + "." + cents_str[3:]
# dollars = float(dollars_str)
# print(cents / 100)
# print(dollars)
# print("$" + dollars_str)


# additional operations
# former = "sam I am"
# latter = "I am sam"
# print()
# print("am I" in former)             # substring testing
# print("am I" in latter)
# print()
# print(former == latter)             # comparison
# print(former < latter)              # by lexicographic order
# print(former > latter)
# print(former.lower())               # calling a str method .lower()
# print(former < former.lower())


# additional references
# https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
# https://docs.python.org/3/library/stdtypes.html#string-methods
# https://www.asciitable.com/
