Python Coding Introduction

 

 

 

 

 

 

by Brendon Thiede

Student Goals

  • Understand what Python is and why it's popular
  • Create variables to store information
  • Use print() and input() for two-way conversations
  • Build an interactive text adventure

Icebreaker

If your computer could talk back to you, what's the first thing you'd want it to say?

Let's Get Set Up

Time to get our starter code!

Step 1: Fork the Repository

  1. Go to the workshop repository on GitHub
  2. Click the "Fork" button (top right)
  3. This creates your own copy!

https://github.com/Lansing-Tech-Studio/workshops

https://github.com/Lansing-Tech-Studio/workshops

Already Have a Fork?

If you forked for a previous workshop, update it first:

  1. Go to your fork on GitHub
  2. Click Sync forkUpdate branch
  3. Then run git pull in your local folder

See the Setup Guide for details

Step 2: Clone to Your Computer


git clone https://github.com/YOUR-USERNAME/workshops.git
cd workshops/
					

Step 3: Open in VS Code


code .
					

This opens VS Code in the current folder

Step 4: Verify Python

Open the integrated terminal (View → Terminal)


python --version
					

You should see Python 3.10 or higher!

On some systems, use python3 --version instead

Step 5: Run Hello World


cd python-intro/starter-code
python hello.py
					

You should see a welcome message!

If it works, you're ready to code!

What is Python?

Python is Everywhere

  • Web apps (Instagram, YouTube, Spotify)
  • Science and data analysis
  • AI and machine learning
  • Games and automation

One of the most popular programming languages in the world

Why Python?

  • Reads like English
  • No curly braces or semicolons needed
  • Great for beginners AND professionals
  • Huge community and tons of resources

Python vs JavaScript

Both are great! Just different tools for different jobs.


// JavaScript
let name = "Alex";
console.log("Hello, " + name);
					

# Python
name = "Alex"
print(f"Hello, {name}")
					

Python is often considered easier to read

Variables

Labeled boxes for storing information

Why Do We Need Variables?

To remember information and use it later!

  • A player's name
  • A score that changes
  • A choice the user made
  • Story elements

Creating Variables in Python

Just pick a name and use =


name = "Scooby"
snacks = 7
pi = 3.14
					

No special keywords needed - Python figures it out!

Naming Rules

  • Start with a letter or underscore
  • No spaces (use snake_case instead)
  • Can't use special keywords (like print, if)
  • Be descriptive!

# Good names
player_name = "Sam"
current_score = 100

# Bad names
x = "Sam"        # What is x?
n = "Sam"         # Which name?
my name = "Sam"   # Has a space!
					

Data Types

Different kinds of information

Strings

Text wrapped in quotes


greeting = "Hello, world!"
name = "Scooby"
story = 'Once upon a time...'
					

Use double quotes " " or single quotes ' '

Numbers

Integers (whole) and floats (decimal)


age = 13          # integer (int)
score = 100       # integer
pi = 3.14         # float
temperature = 72.5  # float
					

Can do math with numbers!

Booleans

True or False values (capitalized!)


is_learning = True
has_finished = False
loves_python = True
					

Great for yes/no questions!

Activity: Your First Variables

Open adventure.py and create variables about yourself:


my_name = "put your name here"
my_age = 0  # put your age
is_learning_python = True
					

Run it: python adventure.py

print()

Seeing what your program is doing

Why print()?

  • Displays information in the terminal
  • Shows you what variables contain
  • Helps you debug (find mistakes)
  • Your programming superpower!

Using print()


name = "Alex"
print(name)
					

Output:


Alex
					

Printing Different Things


print("Hello!")
print(42)
print(True)
print("Score:", 100)
					

Output:


Hello!
42
True
Score: 100
					

f-strings

The easy way to mix variables and text

How f-strings Work

Put f before the quotes, variables in {}


name = "Alex"
age = 13
print(f"My name is {name}")
print(f"I am {age} years old")
					

Output:


My name is Alex
I am 13 years old
					

Much cleaner than concatenation!

input()

Asking the user questions

How input() Works

Shows a prompt, waits for the user to type, returns their answer


name = input("What is your name? ")
print(f"Hello, {name}!")
					

Output:


What is your name? Alex
Hello, Alex!
					

Important: input() Returns a String

Even if the user types a number, it's text!


# This is a string "13", not the number 13
age = input("How old are you? ")

# Convert to a number with int()
age = int(input("How old are you? "))
					

Use int() for whole numbers, float() for decimals

Activity: Interactive Greeting

Add to your adventure.py:


name = input("What is your name? ")
color = input("What is your favorite color? ")
print(f"Hello, {name}!")
print(f"Great choice - {color} is awesome!")
					

Run it: python adventure.py

Project Energizer

Would you rather...

  • Have a robot that cleans your room, or one that does your homework?

Your Mission

Create an interactive text adventure!

What is a Text Adventure?

  • A story where the player makes choices
  • The program asks questions and responds
  • Different choices lead to different outcomes
  • Like a choose-your-own-adventure book!

New Concept: if / else

Making decisions in code


choice = input("Go left or right? ")

if choice == "left":
    print("You found a treasure chest!")
else:
    print("You found a friendly dragon!")
					

== checks if two things are equal

Indentation Matters!

Python uses spaces to group code together


if choice == "left":
    print("This is inside the if")
    print("This is also inside the if")

print("This is outside - always runs")
					

Use 4 spaces (or press Tab) to indent

Example Adventure


hero = input("What is your name, adventurer? ")
print(f"{hero} enters the Dark Forest...")

choice = input("Do you take the path or the river? ")

if choice == "path":
    print(f"{hero} found a hidden village!")
else:
    print(f"{hero} discovered a waterfall!")
					

Your Template

Open adventure.py - it has TODO comments to guide you!

Build your adventure step by step:

  1. Set up variables
  2. Ask the player's name
  3. Create the opening
  4. Add a choice with if/else
  5. Write the ending

Hands-On: Build Your Adventure!

Getting Help

  • Run it frequently with small changes: python adventure.py
  • Read the error messages - they're helpful!
  • Check for missing colons after if/else
  • Check your indentation (4 spaces)
  • Ask an instructor
  • Help your neighbor

Everyone makes mistakes - that's how we learn!

If You Finish Early

  • See if you can help a neighbor
  • Add more choices with elif
  • Track a score variable
  • Ask for more user inputs
  • Add more story branches
  • Make your adventure longer!

Remember

Your adventure is unique!

There's no "right" story - be creative!

The goal is to practice variables, input, and if/else

Save Your Work

Let's commit to Git!

Git Commands


git add .
git commit -m "Complete text adventure"
git push
					

Now your work is saved on GitHub!

Show & Tell

Who wants to share their adventure?

Wrap-Up

What We Learned

  • Python is popular and reads like English
  • Variables store information
  • Data types: strings, integers, floats, booleans
  • print() displays output
  • input() gets user input
  • f-strings format text with variables
  • if/else makes decisions

Reflection

What surprised you about Python?

What would you add to your adventure with more time?

Coming Up Next

Advanced Python Coding

Your code will use loops to repeat actions!

You'll use lists to store collections of data!

Keep Practicing

  • Expand your adventure
  • Experiment with variables
  • Try the Python REPL: type python
  • Check out the Next Steps guide
Questions?

Thank you!