> Source URL: /demos/cs1-path/labs/lab-01.spec
---
lab_number: 1
title: Hello Python
outcomes: [1, 6]
difficulty: beginner
prerequisites: []
estimated_time: 60-90 minutes
---

# Lab 1: Hello Python

## Overview

Welcome to your first programming lab! Today you'll write your first Python programs, learn how to store information in variables, and practice basic input/output operations.

## Learning Objectives

By completing this lab, you will be able to:

- [ ] Run Python code and see the output
- [ ] Create variables to store different types of data
- [ ] Use `print()` to display information
- [ ] Use `input()` to get information from the user
- [ ] Perform basic calculations with Python

## Prerequisites

- Python installed on your computer
- A code editor (VS Code recommended)
- Curiosity and patience!

## Setup

1. Open your code editor
2. Create a new file called `lab1.py`
3. Save it somewhere you can find it later

## Instructions

### Part 1: Your First Program

Every programmer starts here. Let's write the classic "Hello, World!" program.

1. Type this code in your file:

```python
print("Hello, World!")
```

2. Run your program (in VS Code, click the play button or press F5)

**Expected output:**

```
Hello, World!
```

Congratulations—you just wrote your first program! The `print()` function displays text on the screen. The text inside the quotes is called a **string**.

3. Try changing the message. Make Python say something else:

```python
print("Python is fun!")
```

### Part 2: Variables

Variables are like labeled boxes that store information. Let's create some.

1. Create variables to store your information:

```python
# Storing text (strings)
name = "Alex"
favorite_color = "blue"

# Storing numbers (integers)
age = 20
year = 2025

# Storing decimal numbers (floats)
height = 5.8
gpa = 3.7
```

2. Print your variables:

```python
name = "Alex"
print(name)
print("My name is", name)
```

**Expected output:**

```
Alex
My name is Alex
```

3. Now try combining variables in a print statement:

```python
name = "Alex"
age = 20
print(name, "is", age, "years old")
```

**Expected output:**

```
Alex is 20 years old
```

### Part 3: Getting User Input

Programs become more interesting when they interact with users.

1. Ask the user for their name:

```python
name = input("What is your name? ")
print("Hello,", name)
```

Run this program. Notice it waits for you to type something and press Enter.

**Example interaction:**

```
What is your name? Jordan
Hello, Jordan
```

2. Create a program that asks for two pieces of information:

```python
name = input("What is your name? ")
color = input("What is your favorite color? ")
print(name, "likes the color", color)
```

### Part 4: Basic Math

Python can work as a calculator. Let's do some math!

1. Try these operations:

```python
# Addition
total = 5 + 3
print("5 + 3 =", total)

# Subtraction
difference = 10 - 4
print("10 - 4 =", difference)

# Multiplication
product = 6 * 7
print("6 * 7 =", product)

# Division
quotient = 15 / 3
print("15 / 3 =", quotient)
```

2. Create a program that calculates the area of a rectangle:

```python
length = 8
width = 5
area = length * width
print("A rectangle with length", length, "and width", width)
print("has an area of", area)
```

**Expected output:**

```
A rectangle with length 8 and width 5
has an area of 40
```

### Part 5: Putting It Together

Now let's combine everything you've learned!

Create a program called `greeting.py` that:

1. Asks the user for their name
2. Asks the user for their birth year
3. Calculates their approximate age
4. Prints a personalized greeting

```python
# Get user information
name = input("What is your name? ")
birth_year = input("What year were you born? ")

# Calculate age (we need to convert the input to a number)
birth_year = int(birth_year)
current_year = 2025
age = current_year - birth_year

# Print the greeting
print("Hello,", name + "!")
print("You are approximately", age, "years old.")
```

**Example interaction:**

```
What is your name? Sam
What year were you born? 2003
Hello, Sam!
You are approximately 22 years old.
```

## Submission

1. Create a final program called `about_me.py` that:

   - Stores your name in a variable
   - Stores your major/intended major in a variable
   - Stores the number of credits you're taking in a variable
   - Asks the user how many hours they study per week
   - Calculates study hours per credit
   - Prints all this information in a nice format

2. Push your `lab1.py` and `about_me.py` files to your GitHub repository

## Self-Check

Before submitting, verify:

- [ ] Both files run without errors
- [ ] Variables have meaningful names (not `x`, `y`, `z`)
- [ ] Your `about_me.py` program uses at least 3 variables
- [ ] Your program correctly calculates study hours per credit

## Extension Challenges (Optional)

1. **Temperature Converter**: Write a program that asks for a temperature in Fahrenheit and converts it to Celsius. Formula: `celsius = (fahrenheit - 32) * 5/9`

2. **Mad Libs**: Create a simple mad libs game that asks for a noun, verb, and adjective, then prints a silly sentence using them.

## Getting Help

- Review [Lecture 1: Variables & Types](../lectures/lecture-01.slides.md)
- Check the course discussion forum
- Attend office hours


---

## Backlinks

The following sources link to this document:

- [Lab 1: Hello Python](/demos/cs1-path/index.path.llm.md)
- [Lab 1: Hello Python](/demos/cs1-path/course.outcomes.llm.md)
- [Lab 1: Hello Python](/demos/cs1-path/labs/lab-02.spec.llm.md)
- [Lab 1: Hello Python](/demos/cs1-path/labs/lab-03.spec.llm.md)
- [Lab 1](/demos/cs1-path/lectures/lecture-01.slides.llm.md)
- [Lab 1: Hello Python](/demos/cs1-path/course.schedule.llm.md)
