Lesson 7.7: Continue Project Work – Functions & Error Handling

Today’s Goals

  • Add more functionality to your project
  • Organize code with functions
  • Improve reliability with error handling

Warm-Up Question

  • What is one bug you hit during your last coding session?

Why Functions?

  • Break large code into reusable parts
  • Easier to test small pieces

Example

def greet_user():
    name = input("What is your name? ")
    print("Hello,", name)

greet_user()

Error Handling Basics

try:
    num = int(input("Enter a number: "))
    print("You entered", num)
except ValueError:
    print("That’s not a valid number!")

Class Activity

  • Add at least one function to your project
  • Add one try/except block to handle bad input

Teacher Checkpoints

  • By halfway through class: show one new function working
  • By the end: show input safety added

Student Challenge

  • Create a function that loops until valid input is entered

Wrap-Up

  • Functions + error handling make programs stronger
  • Next time: Project checkpoint review