Want to create interactive content? It’s easy in Genially!
Writing a Python Script
Ria Dalvi
Created on March 11, 2025
Start designing with a free template
Discover more than 1500 professional designs like these:
Transcript
Writing a Python Script
Learn how to create, run, and under your first Python script.
Start
Objectives
By the end of this guide, you will:
- Install Python on your machine.
- Write a simple Python script.
- Run the script and understand its output.
- Learn basic Python syntax (variables, loops, and functions).
Modules and Summary
Index
Activities
Evaluation
Getting Started with Python
Learn how to install Python and set up your environment.
Modules
Writing Your First Script
Learn how to write and run your first script.
Enhancing Your Script
Learn how to add instructions to enhance your script.
Getting Started with Python
What is Python?
- Python is powerful yet beginner-friendly programming language known for its clarity and flexibility
- Some of its key feature include:
- Easy to learn and write (uses plain English-like syntax)
- Versatile (works for web apps, AI, automation, and more)
- Huge community support and libraries
+Info
Getting Started with Python
Installing Python
- Go to the official Python website: https://www.python.org/downloads/
- Download the latest version of Python for your operating system (Windows, Mac, or Linux).
- During installation, check the box that says "Add Python to PATH" (this makes it easier to run Python from the command line).
Verify your installation by opening a terminal or command prompt and typing:python --version
Getting Started with Python
Setting up Your Environment
- Create a folder for your Python projects using these commands:
- mkdir python-projects
- cd python-projects
- Create a new file for your script:
- touch my_first_script.py
- Install a text editior like:
- VS Code
- Sublime Text
Folder structure for python project
Writing Your First Script
Writing a Script
- Open my_first_script.py in your text editor.
- Add the following code:
- print("Hello, World!")
- Save the file.
Writing Your First Script
Running the Script
- Open a terminal or command prompt.
- Navigate to your project folder:
- cd path/to/python-projects
- Run the script:
- python my_first_script.py
- You should see the output:
- Hello, World
+ Activity 1
Enhancing Your Script
Add Variables and User Input
- Update your script to include variables and user input:
- name = input("What's your name? ")
- print(f"Hello, {name}! Welcome to Python."
- Run the script and interact with it.
+ Activity 2
Enhancing Your Script
Add a Loop
- Modify your script to include a loop:
- times = int(input("How many times should I greet you? "))
- for i in range(times):
+ Activity 3
Enhancing Your Script
Add a Function
- Add a function to make your script more modular:
- def greet_user(name, times):
+ Activity 4
Activity 1
First Script Activity
Activities
Activity 2
Variables and Input Activity
Write a great subtitle hereto provide context
Activity 3
Loops Activity
Activity 4
Functions Activity
Back to Module
Activity Relate key concepts
Activity 1
Modify the script to print your name instead of "Hello, World!" and run it again.
Solution
Back to Module
Activity Relate key concepts
Activity 2
Modify the script to ask for the user’s age and print a personalized message (e.g., "You are 25 years old.").
Solution
Back to Module
Activity Relate key concepts
Activity 3
Modify the loop to count down instead of up (e.g., "Hello, Alice! (Time 3)").
Solution
Back to Module
Activity Relate key concepts
Activity 4
Add a new function that asks for the user’s favorite color and prints it.
Solution