Want to create interactive content? It’s easy in Genially!

Get started free

Building Your First Python Program:

Apollo Parnas

Created on March 11, 2025

Start designing with a free template

Discover more than 1500 professional designs like these:

Transcript

Building Your First Python Program:

Learn Variables, Inputs, and Conditionals in 1 Hour!

Start

Introduction

What do I need before I begin?This guide is intended for beginners with no coding experience. As long as you can comfortably navigate your computer, you are ready to begin! If you're curious why Python is so useful and popular, check out the video below!

Index

Activities
Objectives
Evaluation
Modules

Objectives

- Create variables and use input() to interact with users in Python. - Write conditional statements (if/elif/else) to control program logic. - Build a functional calculator that performs basic arithmetic operations (+, -, *, /). - Troubleshoot common errors, such as type conversion issues (e.g., converting strings to numbers). - Use an online code editor (like Replit) or install Python locally to run your programs. - Modify code to add new features (e.g., squaring a number). - Create a complete program that you will fully understand

'I will be able to create simple Python programs with the knowledege I gain from this learning module'

Modules

We reccommend you follow these modules in order but if you feel you don't need a certain section feel free to skip ahead!

More Coding

Basic Coding

Setup

We will use conditionals to add more functionality to our program.

In this section we will be writing the basic functions of our python program.

This section will help you understand how to begin coding in a language, in this case Python.

01

Setting up Python

Skip this section if you have used Python before and know how to begin writing a Python program.

01

Option 1: Use an Online Editor

For those who want to start coding immediately without installing software, use Replit, a free online coding platform: 1. Go to https://www.online-python.com/ 2. Start Coding: On the top left side, you’ll see a file named main.py. Within this file is where you’ll write your code. 3. Clear the code inside and type "print("Hello!")" in the editor, then click the green “Run” button beneath the code. You’ll see “Hello!” printed in the console on the right. Congrats—you’re ready to code! 4. Save Your Work:The editor saves automatically, but you can rename your project anytime by clicking the save icon

01

Option 2: Download and Run

This explanation will be based on a windows system but the instructions should work for mac os as well: 1. Download Python: Go to python.org/downloads. Click the yellow “Download Python” button (e.g., Python 3.13). 2. Install Python: Open the downloaded file and check the box: “Add Python to PATH” (this lets you run Python from any folder). You may not need to do this on mac. Click “Install Now” and wait for the installation to finish. 3. Write Your First Program: Open Notepad (Windows) or TextEdit (Mac). Type print("Hello!"), then save the file as hello.py (select “All Files” as the file type). 4. Run the Program: Open the Command Prompt (Windows: search “cmd” in Start Menu). Navigate to your file’s folder using cd and the file location. Type python hello.py and press Enter. You’ll see “Hello!” printed.

Common Issues, Click any sections that may apply to you

"Python not recognized"

Code doesn’t run

“File not saved”

“Permission denied”

Mac/Linux Download Issue

Online Issue

OnlineIssue

Windows/Mac Download Issue

02

Writing Your First Code

In this section we will create a basic calculator program in python

02

Step 1: Understand Key Concepts

1. Variables: Containers that store data (like numbers or text). - Example: num1 = 5 stores the number 5 in a variable named num1. Input: How your program asks the user for data. - Use input("Enter a number: ") to get text from the user. Output: How your program shows results. - Use print("Result: " + str(result)) to display text and numbers.

02

Step 2: Writing the code

# Ask for the first number and convert it to a float (decimal) num1 = float(input("___: ")) # Hint: Replace ___ with "Enter first number" # Ask for the second number num2 = float(input("___: ")) # Hint: Use "Enter second number" # Add the numbers and store the result result = ___ + ___ # Fill in the variable names (num1 and num2) # Show the result print("The sum is: " + ___(result)) # Hint: Convert the number to text with str()

02

Step 3: Running the code

Click Run or type python your_file.py (local). Enter numbers like 3 and 5. You should see: The sum is: 8.0

Having Errors? Click this button!

03

Adding Conditionals

Developing your program further

03

Step 1: Understand Conditionals

Conditionals: Code that makes decisions based on conditions. Example: if user_chooses "+": add_numbers() else: print("Invalid operation")

03

Step 2: Build the Operation Logic

num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) # Ask the user to choose an operation operation = input("Choose +, -, *, or /: ") # Determine which operation to perform if operation == "+": result = num1 ___ num2 # Fill in the operator (+) elif operation == "-": result = num1 ___ num2 # Fill in the operator (-)

elif operation == "*": result = ___ # Multiply num1 and num2 elif operation == "/": result = ___ # Divide num1 by num2 else: print("Invalid operation!") # Display the result (if valid) if operation in ["+", "-", "*", "/"]: print("Result: " + str(result))

03

Step 3: Debug

Error: SyntaxError: invalid syntax Fix: Check for missing colons : after if/elif/else or typos in ==. Error: Division by zero crashes the program Fix (Bonus): Add if num2 == 0: print("Cannot divide by zero!") before dividing. Error: No output when choosing "/" Fix: Ensure the final print() is indented correctly under the if statement.

Activities Show what you know!

Activity 2

Activity 1

Look at your program in detail!

Match the terms you have learned to the correct concepts!

Activity 1

Solution
Click on the correct concepts
Variables and Input Output
Conditionals and Operators
input
else
input
else
elif
float
elif
float
if
print
if
print
str
str
00:10

Activity 2

Click on the first Variable, Input and Output

num1 is the first variable we declare

On the same line, we take our first input

Even though it is behind a conditional, this print is our first output

Assessment

In this section, you will have the opportunity to test your acquired knowledge throughout the course. Our interactive quiz will provide a detailed assessment of your understanding of key topics. Get ready to challenge your skills and reinforce your learning as you move towards mastering the fundamental concepts. Don't miss the chance to demonstrate everything you've learned so far!

1/4

2/4

3/4

4/4

Course completed!

The site should saves automatically, but rename your project and try saving to a different location manually

- On Mac/Linux, use python3 hello.py instead. - Make sure you’re in the correct folder with cd [folder-name].

- Restart your computer after installing Python. - Reinstall Python and check “Add Python to PATH” during installation.

Fix: Refresh the page or click “Stop” and “Run” again.

Close
input
else
float
elif
print
if
str

Common Errors

Downloaded and Online Errors

Error: NameError: name 'num1' is not defined Fix: Check your variable names (they must match exactly!). Error: ValueError: could not convert string to float Fix: Make sure the user enters numbers (not letters!). Blank output? Fix: Did you forget print()?