Welcome to the Python Launchpad! If you have ever wanted to learn to code but didn’t know where to start, you are in the right place.
Many people think programming is just for math geniuses or computer wizards. The truth? Programming is just writing instructions. If you can write a grocery list, you can learn Python.
In this first module, we are going to cover the absolute basics: how to make the computer speak, how to store information, and how to make the computer listen to you.
1. Speaking to the Computer: print()
The very first thing every programmer learns is how to make the computer display text on the screen. In Python, we do this using a function called print.
Think of a function like a machine: you put something in, and it does something.
The Code:
Python
print("Hello, World!")
Key Rules:
- Parentheses
(): These tell Python to execute the function. - Quotes
"": These tell Python that the text inside is just text (a String), not a command.
2. Storing Information: Variables
Imagine you are moving into a new house. You have a box, and you write “Kitchen Stuff” on the outside. Inside, you put plates.
In Python, Variables are those boxes.
- The Label: The name of the variable.
- The Contents: The data you store inside.
The Code:
Python
# We create a variable named 'player_name' and store "Alex" inside it
player_name = "Alex"
# We create a variable named 'score' and store the number 100 inside it
score = 100
print(player_name)
print(score)
Why is this useful? Because if the player’s name changes to “Sam,” you only have to change it in one place!
3. Data Types: Text vs. Numbers
Computers need to know what kind of data they are looking at.
- String (
str): Text. Always wrapped in quotes.- Example:
"Hello","Pizza","123"(if it’s in quotes, it’s text!)
- Example:
- Integer (
int): Whole numbers. No quotes.- Example:
5,10,42
- Example:
- Float: Numbers with decimals.
- Example:
3.14,9.99
- Example:
4. Listening to the User: input()
A program is boring if it only talks. Let’s make it listen. The input() function pauses the program and waits for the user to type something on their keyboard and hit Enter.
The Code:
Python
print("What is your name?")
name = input()
print("Nice to meet you, " + name)
Pro Tip: You can put the question inside the input parentheses to save a line of code:
Python
name = input("What is your name? ")
🎓 Module 1 Final Project: “The Bio Generator”
Now it is your turn! We are going to build a program that asks the user for details and creates a funny biography.
The Challenge:
- Ask the user for their name.
- Ask the user for their favorite color.
- Ask the user for their favorite food.
- Print a sentence that combines all three variables.
The Solution:
Try to write it yourself first! If you get stuck, highlight the box below to see the answer.
Python
# 1. Get the inputs name = input("Enter your name: ") color = input("Enter a color: ") food = input("Enter a food: ")
2. Print the result
print(“Here is ” + name + “!”) print(“They love ” + color + ” jackets and eating ” + food + “.”)
