Week 2 · Session 2

Saving Your Work, Then Real Python

Git workflow, variables, operators, and Lab 1.

Saving Your Work

One-Time Setup

Only the first time you use git on a new computer.

  • git config --global user.email "you@allegheny.edu"
  • git config --global user.name "Your Name"
  • This tells git who to credit for your commits. Do it once here, never again on this computer

Saving Your Work

Git in the Terminal

Three commands, every time you save progress to GitHub.

  • git add . — stage every changed file
  • git commit -m "message" — save a snapshot
  • git push — upload it to GitHub

Saving Your Work

Git in VS Code

Same three steps, with buttons instead of typing.

  • Open the Source Control panel in the left sidebar
  • Click + next to a file to stage it — this is git add
  • Type a message, click the checkmark — this is git commit
  • Click Sync Changes (or ↑) to push

Variables and Types

Your first Python.

  • trip_miles = 450 — the name goes on the left, the value on the right. = means store this, not equality
  • The name is for humans. m tells nobody anything; trip_miles tells them everything
  • Four types you will use constantly: int (26), float (3.79), str ("Wednesday"), bool (True/False)
  • Print with an f-string: print(f"Trip: {trip_miles} miles")

input() Always Gives You a String

Always. Even when the user types a number.

  • input() pauses the program, waits for the user to type a line and press Enter, then hands back what they typed
  • age = input("How old? ") then typing 19 stores "19", not 19
  • "19" + 1 is an error. Convert first: age = int(input("How old? "))

Try It Now

Run the code below. Fix it. Break something else on purpose.

  • Add a string to a number and read the error message carefully
  • Convert a word with int() and read that error too
  • Error messages are documentation. Learn to read them

              

Arithmetic, Especially %

The operators Lab 1 runs on.

  • + - * — the ones you already know. / always gives a float: 10 / 5 is 2.0
  • // — integer division, throws away the remainder: 2026 // 100 is 20
  • % — modulo, keeps only the remainder: 11 % 7 is 4. Anything that wraps around (clocks, weekdays) is modulo
  • "1-23-2026".split("-") gives ["1", "23", "2026"] — every piece is still a string, convert before you calculate

Your Turn

  • 145 minutes is 2 hours and 25 minutes. Two operators are wrong
  • Then use .split("-") on the last line

              

Released Today

Lab 1: The Doomsday Algorithm

Due Friday, September 11.

  • Given a date, calculate its day of the week. Anchor days and helper functions are already provided in DayFunctions.py
  • Split the date, convert the pieces, and combine the arithmetic. Worth 4.5 points; code review is graded separately
  • Push your work today, even if unfinished — git add ., commit, push
  • Run uv run gatorgrade --config gatorgrade.yml before you consider it done, and book a code review early
← Exit
1 / 10