Part 2: Variables, Data Types, and Basic Input/Output (with AI Support)

In this part of the series, we’ll dive into three essential Python concepts:

  • Variables and data types
  • Getting input from users
  • Displaying and formatting output

Plus, we’ll show you how to leverage AI tools like ChatGPT to help practice and learn more effectively.


🧠 What Are Variables?

Variables are like labeled containers for storing data. In Python, you don’t need to declare the type — it figures it out for you.

name = "Alice"
age = 25
is_student = True

You’ve just created:

  • A string ("Alice")
  • An integer (25)
  • A boolean (True)

🧪 Try It Yourself:

Open your editor or Replit and write:

name = input("What is your name? ")
age = input("How old are you? ")

print("Hello, " + name + "! You are " + age + " years old.")

💡 Note: Everything from input() comes in as a string. If you need it as a number, use int() or float().


🔢 Common Data Types

TypeExampleDescription
int42Whole numbers
float3.14Decimal numbers
str"hello"Text
boolTrue / FalseBoolean values

You can check the type of any variable:

print(type(age))

🧠 AI Tip: Use ChatGPT to Generate Practice Problems

Ask ChatGPT:

“Give me 5 beginner Python exercises to practice using input()print(), and variables.”

You’ll get instant, tailored practice questions — no need to search through outdated forums.


🔤 String Formatting (Make Your Output Look Good)

Instead of this:

print("Hello, " + name + "! You are " + age + " years old.")

Try this with f-strings (recommended in Python 3.6+):

print(f"Hello, {name}! You are {age} years old.")

Cleaner and easier to read!


🔍 AI Debugging Tip

Stuck on an error? Copy your code and ask ChatGPT:

“Why am I getting this error in my Python code?”

You’ll get an explanation — often with a corrected version of your code.


🧰 Free Tools to Reinforce What You’ve Learned


🎯 Practice Challenge

Write a Python script that:

  • Asks the user for their name and birth year
  • Calculates their age (assume the current year is 2025)
  • Prints a friendly message with their name and age

Bonus: Ask ChatGPT to review your script and suggest improvements.


🏁 Coming Up in Part 3…

We’ll tackle conditional logic using ifelif, and else. You’ll learn how Python makes decisions — and how AI can help generate logic puzzles and real-world decision-making scenarios.

Share the Post:

Related Posts

Join the Codexa Crew – It’s free!

Stay Updated with the Latest in Tech & Automation

Be the first to know when new content drops on Green Codexa!