"""
GLAMWalk -- Volume 1: Foundations
04_python_basics.py

A runnable primer covering every core piece of Python grammar this series leans on: comments, variables, f-strings, comparisons, if/elif/else and the ternary shorthand, lists, dictionaries, for loops, and functions. Run it top to bottom, or copy pieces out to experiment. Matches Volume One, Section 1.5.

Source: Volume One, Section 1.5 -- The Bare Minimum Grammar You Need Before Chapter 2
Targets Python 3.11.4 -- see Volume One, Chapter 1.5/1.6.
"""

# This whole line does nothing when the program runs.
print("Hello, GLAM.")   # Python ignores everything from the # onward, even here.


title = "Sunflowers"
year = 1889
is_public_domain = True

print(title)
print(year)
print(is_public_domain)


object_id = 436535
url = f"https://collectionapi.metmuseum.org/public/collection/v1/objects/{object_id}"
print(url)
# https://collectionapi.metmuseum.org/public/collection/v1/objects/436535


year = 1889

print(year < 1930)     # True  — is year less than 1930?
print(year == 1930)    # False — is year EXACTLY equal to 1930?
print(year != 1930)    # True  — is year NOT equal to 1930?


year = 1889

if year < 1900:
    print("That's from the 1800s.")
elif year < 2000:
    print("That's from the 1900s.")
else:
    print("That's from the 2000s or later.")


year_found = True

label = "known" if year_found else "unknown"
print(label)   # "known"


titles = ["Sunflowers", "The Starry Night", "Irises"]

print(titles[0])     # "Sunflowers"    — Python counts positions starting at 0, not 1
print(titles[1])     # "The Starry Night"
print(len(titles))   # 3               — how many items are in the list

print(titles[:2])    # ["Sunflowers", "The Starry Night"]  — a "slice": everything up to (not including) position 2


artwork = {"title": "Sunflowers", "artist": "Van Gogh", "year": 1889}

print(artwork["title"])          # "Sunflowers" — look up by key, in square brackets
print(artwork.get("title"))      # same result, written a different way
print(artwork.get("medium"))     # None — no crash, because .get() has a safe fallback built in
print(artwork.get("medium", "Unknown"))   # "Unknown" — .get() lets you supply your OWN fallback


titles = ["Sunflowers", "The Starry Night", "Irises"]

for title in titles:
    print("Title:", title)


def describe_year(year):
    """A short description of what this function does — this is a docstring."""
    if year < 1930:
        return "old enough to likely be public domain"
    else:
        return "too recent to assume public domain"

print(describe_year(1889))
print(describe_year(2020))


if __name__ == "__main__":
    # code here only runs when this file is executed directly —
    # not when some OTHER file imports functions from it
    ...
