Python Starter

Written by

in

Python Starter Crash Course: Code Confidently in 60 Minutes Welcome to Python! This fast-paced guide will teach you the absolute essentials of programming. By the end of this hour, you will understand how Python thinks and how to write your own functional code. Let’s get started. Minute 0–10: Setup and Your First Line of Code

Python is famous for its clean, readable syntax. It looks almost like regular English.

To run Python code instantly without installing anything, open your browser and go to Google Colab or Repl.it.

In your editor, type the following line and hit the run button: print(“Hello, World!”) Use code with caution. What just happened?

print() is a built-in function that displays text on your screen. The text inside the quotation marks ”” is called a string. Minute 10–20: Variables and Data Types

Variables are digital storage boxes. You use them to store data so you can use or change it later. In Python, you create a variable simply by assigning it a value using the = sign.

# Storing data in variables user_name = “Alex” # String (text) user_age = 25 # Integer (whole number) user_height = 5.9 # Float (decimal number) is_student = True # Boolean (True or False) # Using variables print(user_name) print(userage + 5) Use code with caution. Key Rules: Variable names cannot have spaces; use underscores ().

Do not put quotation marks around numbers if you want to do math with them.

Python reads code from top to bottom. If you reassign a variable, it takes the newest value. Minute 20–35: Making Decisions (Conditionals)

Programs become smart when they can make choices. We use if, elif (else if), and else statements to check if conditions are true.

Python uses indentation (four spaces or a tab) to know which code belongs inside the decision block.

score = 85 if score >= 90: print(“Grade: A”) elif score >= 80: print(“Grade: B”) else: print(“Grade: C”) Use code with caution. How it works:

Python checks the first if. If it is false, it moves to the elif.

If none of the conditions match, it defaults to the else block.

Notice the colons : at the end of each condition. Missing these is the most common beginner mistake! Minute 35–45: Lists and Loops

Instead of creating twenty variables for twenty pieces of data, you can store them all in a single List. Lists use square brackets [].

# A list of favorite fruits fruits = [“apple”, “banana”, “cherry”] # Accessing items by position (Python starts counting at 0) print(fruits[0]) # Outputs: apple Use code with caution.

If you want to perform an action on every single item in a list, you use a for loop. for fruit in fruits: print(“I want to eat a ” + fruit) Use code with caution.

The loop automatically starts at the beginning of the list, assigns the current item to the temporary variable fruit, runs the indented code, and repeats until the list ends. Minute 45–55: Functions (Your Code Shortcuts)

Functions are reusable blocks of code. Instead of writing the same ten lines of code over and over, you write them once inside a function and “call” it whenever you need it. We define a function using the def keyword.

# Defining the function def greet_user(name): message = “Welcome back, ” + name + “!” return message # Using the function player1 = greet_user(“Sarah”) player2 = greet_user(“David”) print(player1) print(player2) Use code with caution. Key terms:

name is a parameter—a placeholder for data the function needs to do its job. return sends the final result back to the main program. Minute 55–60: Putting It All Together

Let’s combine everything you just learned into a single mini-program: a smart shopping cart calculator that gives a discount if you buy too much.

# 1. Variables and Lists cart_prices = [10, 25, 5, 40, 15] # 2. Function to calculate total def calculate_total(prices_list): total = 0 # Loop through items for price in prices_list: total = total + price return total # 3. Running the function final_bill = calculate_total(cart_prices) # 4. Conditionals for a discount if final_bill > 80: final_bill = final_bill - 10 print(“You got a \(10 discount!") print("Your total is: \)” + str(final_bill)) Use code with caution. You Did It!

In just 60 minutes, you went from zero to writing a functional automation script. You have mastered variables, data types, logic, loops, and functions.

The best way to build confidence from here is to experiment. Try changing the numbers in the code blocks above, introduce errors on purpose to see how Python responds, and start building your own small projects!

If you want to practice your new skills right now, let me know what kind of project sounds fun to you. I can provide the next steps for building a text adventure game, a simple calculator, or a guessing game application.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *