Search⌘ K
AI Features

Solution: Write a Character Introduction

Explore how to create a character introduction by storing various attributes like name, species, and age in Python variables. Learn to combine strings and numbers using print statements to display a formatted description, building foundational skills in handling data and output in Python.

We'll cover the following...

In this example, we’re creating a character profile using multiple variables to store different pieces of information about the character.

  • Each line before print() stores information in a variable:

    • name, species, home_planet, and special_ability are strings (text values inside quotes).

    • age is a number (integer).

  • The print() statements display a short description using these variables.

  • The + sign is used here to join text parts together (for example, adding "." or "!" at the end of a sentence).

  • Commas in print() separate words and variables, and Python automatically adds spaces between them.

Python
name = "Zorblax"
species = "alien"
age = 402
home_planet = "Nebulon-5"
special_ability = "teleportation"
print("Meet", name, "a", age, "year-old", species, "from", home_planet + ".")
print(name, "has an incredible power:", special_ability + "!")