############################################################
# string operations and methods
############################################################


# Strings can be written using single-quotes, double-quotes, or
# triple quotes. On their own, single-quotes and double-quotes
# can be used interchangeably, but double-quotes can be used
# within single-quote strings. Triple-quotes are used for multi-line
# strings.

s1 = "Hi my name is Jake"
s2 = 'Hi my name is Jake'
print(s1)
print(s2)

s3 = 'Jake said "Hi"'
print(s3)

s4 = '''This is a string
        on multiple lines.'''
print(s4)


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


# EXERCISE
s1 = "Hi my name is"
s2 = "Jake"
s3 = "bye"
s4 = "welcome"
# print(s1 + " " + s2)
# print(s3 * 2)
# print(s4[::])
# print(s4[0])
# print(s4[-1])
# print(s4[3])
# print(s4[0:4])
# print(s4[::2])
# print(s4[::-1])
# print(len(s4))


# EXERCISE
a = "Hello"
b = "hello"
c = "goodbye"
# print(a < b)
# print(b < c)


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


# string method documentation:
# https://docs.python.org/3/library/stdtypes.html#string-methods


# EXERCISE
s1 = "Short"

# Write one line of code to produce "SPORT" from s1.


# EXERCISE
s2 = "   hello world!   "

# Write one line of code to produce "helloworld!" from s2.
# Write one line of code to produce "   hello world!" from s2.


# EXERCISE
s3 = "hahaha"
# print(s3.count("a"))
# print(s3.find("ha"))
# print(s3.rfind("ha"))
# print(s3.startswith("h"))
# print(s3.endswith("h"))


# EXERCISE
s4 = "hElLo WoRlD"
# print(s4.capitalize())
# print(s4.title())
# print(s4.swapcase())


# EXERCISE
s1 = "123"
s2 = "abc"
s3 = "abc123"
s4 = "   "
# print(s1.isdigit())
# print(s2.isalpha())
# print(s3.isalnum())
# print(s4.isspace())


# Strings are immutable, meaning that they can't change
# once they're created in memory.

# EXERCISE
s1 = "HELLO"
s2 = s1.lower()
# print(s1)
# print(s2)
# print("h" in s1)
# print("h" in s2)


############################################################
# f-strings
############################################################


# F-strings used to embed expressions inside strings. These
# expressions are evaluated at runtime, and located in {}
# within the string. Any variables within {} must already
# exist before the declaration of the f-string. F-strings can
# also be used for string formatting.

# f-string documentation:
# https://fstring.help


s1 = "Hi my name is Jake"
name = "Jake"

print(s1)
print(f"Hi my name is {name}")


x = 3
y = 4

print(f"x + y = {x + y}")
print(f"x * y = {x * y}")
print(f"x squared = {x ** 2}")


price = 2.5
quantity = 4

print(f"Total: {price * quantity}")
print(f"Total: {price * quantity:.2f}")


# EXERCISE
name = "Jake"
# print(f"{name}_{name[::-1]}")


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


# ticket example from lecture

# With f-strings, we don't need separate strings when
# we want to incorporate commas and spaces!

# When we wanted to print the number of tickets
# that Alyssa, Ben, and Cindy had, we used the
# following code:

alyssa = 2
ben = 4
cindy = 3

print("Alyssa:", alyssa, "tickets")
print("Ben:   ", ben, "tickets")
print("Cindy: ", cindy, "tickets")


# EXERCISE
# Revise the print statements to produce the same 
# output using f-strings.


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


# banking example from lecture

# We can use f-strings to zero-pad and keep
# string widths consistent!

# We used the following code in lecture:

interest_rate = 0.05
days_in_year = 365
daily_rate = interest_rate / days_in_year
daily_multiplier = 1 + daily_rate

balance = 1000

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

for month in range(2, 13):
    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))


# EXERCISE
# Modify the print statement in the for loop so that 
# the trailing 0 shows when the cent value is a 
# multiple of 10.


############################################################
# vscode shortcuts
############################################################


# moving cursor by words
#   opt + left or right on mac
#   ctrl + left or right on windows

# moving cursor across line
#   cmd + left or right on mac
#   home or end on windows

# moving cursor to top or bottom of file
#   cmd + up or down on mac
#   ctrl + home or end on windows


# highlighting words
#   opt + shift + left or right on mac
#   ctrl + shift + left or right on windows

# highlighting lines
#   cmd + shift + left or right on mac
#   shift + home or end on windows


# multi-line cursor (for block editing)
#   cmd + opt + up or down on mac
#   ctrl + alt + up or down on windows


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


# show command palette/search
#   cmd + shift + p on mac
#   ctrl + shift + p on windows


# duplicating lines
#   opt + shift + up or down on mac
#   alt + shift + up or down on windows

# moving lines up and down
#   opt + up or down on mac
#   alt + up or down on windows


# toggle comment
#   cmd + / on mac
#   ctrl + / on windows

# toggle indent
#   cmd + ] or [ on mac
#   ctrl + ] or [ on windows
#   or highlight lines and (shift) + tab


############################################################
# python repl
############################################################


# REPL: Read -> Eval -> Print -> Loop
# The Python REPL automatically prints upon evaluation.
# This is useful for quick testing.


# enter REPL by typing 'python' in the terminal
# >>> s1 = "Hi my name is"
# >>> s2 = "Jake"
# >>> s1
# >>> s2
# >>> s1[0]
# >>> s1[-1]
# >>> s2.upper()
# >>> s2[1:3]
# >>> s1[::2]


# The help() function can be used to quickly access
# documentation about various functions and objects.
# Press q to exit.


# >>> help(range)
# >>> help(int)


# The input() function can be used to interface with a user.
# The function always returns a string.


# >>> input()
# hi
# >>> input()
# 2


# We can write for loops in the REPL!
# To note:
# 1. Indenting is still necessary. Make sure that all code
# within the body of a loop or conditional is still
# indented.
# 2. Variable values are stored within the REPL, just as in
# a normal program. For example, the value of count was
# preserved between the two for loops.


# >>> count = 0
# >>> for i in range(10):
# ...     count += 1
# ...
# >>> count
# >>> for i in range(10):
# ...     count += 1
# ...     print(count)
# ...


# EXERCISE
# What is the value of count after each of the following
# blocks of code? Check your answer by trying out the code
# in the REPL.

# >>> count = 0
# >>> for i in range(10):
# ...     count += 1
# ...     if (count > 5):
# ...         break
# ...
# >>> count

# >>> count = 0
# >>> for i in range(10):
# ...     count += 1
# ...     if (count > 5):
# ...         continue
# ...
# >>> count


# keyboard shortcut to exit the REPL:
#   ctrl+d for mac
#   ctrl+z on windows
