Skip to Content
Course content

Masterclass: Introduction: Project Setup, Print, Input, Variables, and if/else Statements (13:23)

Learn Python by Creating a Pirate Trading Game Like Taipan!

Introduction: Project Setup, Print, Input, Variables, and if/else Statements (13:23)

Video lecture pack · script + deck ready for recording

Session script

Presentation Script — Introduction: Project Setup, Print, Input, Variables, and if/else Statements (13:23)

Learn Python by Creating a Pirate Trading Game Like Taipan! · Masterclass · ~N min

Welcome (slides 1–3)

Hello everyone, and welcome to this Masterclass on learning Python by creating a pirate trading game! I’m excited to guide you through foundational concepts that will help you not only understand Python but also build a fun and engaging game.

In this session, we’ll cover key topics: project setup, using the print function to display messages, gathering input from users, working with variables to store data, and implementing if/else statements for decision-making in your game.

By the end of this lecture, you should feel comfortable with these concepts and be ready to apply them in your pirate trading game.

Motivate Before Mechanics (slides 4–5)

Before we dive into the mechanics, let’s take a moment to think about why these concepts are important. In any game, especially one that involves trading, you need to display information to the player, gather their choices, and react accordingly.

For example, if a player wants to buy cargo, we need to ask how much they want to buy and check if they have enough money. This involves printing messages, getting input, and using variables to track the player’s money and cargo. If/else statements will help us decide what happens based on the player’s choices.

So, let’s get started!

Project Setup (slides 6–7)

First things first, let’s set up our project. Create a new folder for your pirate trading game. Inside this folder, create a new Python file named pirate_trading_game.py. This is where we’ll write our code.

Print Function (slides 8–9)

Now, let’s talk about the print() function. This function allows us to display messages to the user. For example, if we want to greet the player, we can write:

print("Welcome to the Pirate Trading Game!")

When you run this code, it will display the message on the screen. This is crucial for engaging players and providing information.

Input Function (slides 10–11)

Next, we’ll use the input() function to gather information from the player. This function pauses the program and waits for the user to type something. For example, if we want to ask the player for their name, we can write:

player_name = input("What is your name? ")

Here, player_name is a variable that stores the name the player enters. This interaction is vital for personalizing the game experience.

Variables (slides 12–13)

Variables are essential in programming. They allow us to store data that we can use later. In our example, player_name is a variable that holds the player's name.

You can also create variables to track the player's money and cargo. For instance:

money = 100  # Starting money
cargo = 0    # Starting cargo

These variables will help us manage the game state effectively.

If/Else Statements (slides 14–15)

Now, let’s discuss if/else statements. These are used to make decisions in our code. For example, if the player wants to buy cargo, we need to check if they have enough money. Here’s how we can do that:

cargo_price = 20  # Price per unit of cargo
amount_to_buy = int(input("How many units of cargo do you want to buy? "))

if money >= cargo_price * amount_to_buy:
    money -= cargo_price * amount_to_buy
    cargo += amount_to_buy
    print(f"You bought {amount_to_buy} units of cargo.")
else:
    print("You don't have enough money!")

In this code, we first check if the player has enough money. If they do, we deduct the cost from their money and increase their cargo. If not, we display a message saying they don’t have enough money. This decision-making is crucial for gameplay dynamics.

Self-Check Questions (slides 16–17)

Before we move on, let’s take a moment to reflect on what we’ve covered. Here are a few self-check questions:

  1. What is the purpose of the print() function in Python?
  2. How do you gather user input using the input() function?
  3. What is a variable, and why is it important in programming?
  4. How do if/else statements help in making decisions in your code?

Take a moment to think about these questions.

Connect Theory to Real Practice (slides 18–19)

Now, let’s connect these concepts to our pirate trading game. The ability to print messages will enhance the player’s experience by providing feedback and information. Gathering input allows players to make choices, such as how much cargo to buy or sell. Variables will help us keep track of important game data like money and cargo. Finally, if/else statements will enable us to create dynamic interactions based on player decisions.

As you work on your game, remember that these foundational concepts are the building blocks for more complex features.

Recap (slides 20–21)

To recap, we’ve set up our project and covered the basics of printing messages, gathering user input, using variables, and implementing if/else statements. These concepts are crucial for creating interactive experiences in your game.

Discussion Questions (slides 22–23)

Here are some discussion questions to consider:

  1. How can you use the print() function to enhance player engagement in your game?
  2. What types of user input do you think would be important in a trading game?
  3. How can you manage multiple variables to track different aspects of the game, like money and cargo?
  4. In what scenarios would you need to use if/else statements in your game?
  5. What challenges do you anticipate when implementing these concepts in your project?

Take some time to discuss these questions with your peers or reflect on them individually.

Next Lecture (slide 24)

In our next lecture, we’ll learn to work with functions, which will help us organize our code and make it more reusable.

Thank you for joining me today, and I look forward to seeing you in the next session!

Downloads (deck, PDF, markdown sources) are available in the Resources panel on this lesson when you have access.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.

Additional Resources
Join this Course to access resources