Kurssisisältö
Introduction to Python (copy)
Introduction to Python (copy)
Storing Data in Variables
Brilliant work mastering data types! Next, we'll explore how to store data inside variables, much like organizing your groceries into the right bins. This makes your data easy to access and manipulate — key to any efficient coding project.
Watch Alex as he demonstrates how to store data in variables:
Let's put this into practice. Here, we're assigning various types of data to variables, each representing different aspects of a grocery item.
# Storing different types of data in variables item_name = "Banana" item_price = 0.50 item_quantity = 100 in_stock = True print("Item:", item_name) print("Price: $", item_price) print("Quantity:", item_quantity) print("In stock:", in_stock)
This example shows how easily you can access and display the data once it's stored in variables. Notice how each variable type (string
, float
, integer
, boolean
) serves a specific purpose in our grocery analogy.
Swipe to start coding
Define and use variables to represent details of a grocery item — "Eggs". You will assign values for its name, price, quantity, and stock status, then print these details.
- Create a variable
item_name
and assign it the string"Eggs"
. - Create a variable
item_price
and assign it the float3.99
(price per egg). - Create a variable
item_stock_quantity
and assign it the integer120
(number of eggs in stock). - Create a variable
in_stock
and assign it the booleanTrue
(eggs are in stock).
Output Requirements
Print the item details using the following format:
Item: <item_name>
Price per unit: $ <item_price>
Quantity in stock: <item_stock_quantity>
In stock: <in_stock>
Ratkaisu
Kiitos palautteestasi!
Storing Data in Variables
Brilliant work mastering data types! Next, we'll explore how to store data inside variables, much like organizing your groceries into the right bins. This makes your data easy to access and manipulate — key to any efficient coding project.
Watch Alex as he demonstrates how to store data in variables:
Let's put this into practice. Here, we're assigning various types of data to variables, each representing different aspects of a grocery item.
# Storing different types of data in variables item_name = "Banana" item_price = 0.50 item_quantity = 100 in_stock = True print("Item:", item_name) print("Price: $", item_price) print("Quantity:", item_quantity) print("In stock:", in_stock)
This example shows how easily you can access and display the data once it's stored in variables. Notice how each variable type (string
, float
, integer
, boolean
) serves a specific purpose in our grocery analogy.
Swipe to start coding
Define and use variables to represent details of a grocery item — "Eggs". You will assign values for its name, price, quantity, and stock status, then print these details.
- Create a variable
item_name
and assign it the string"Eggs"
. - Create a variable
item_price
and assign it the float3.99
(price per egg). - Create a variable
item_stock_quantity
and assign it the integer120
(number of eggs in stock). - Create a variable
in_stock
and assign it the booleanTrue
(eggs are in stock).
Output Requirements
Print the item details using the following format:
Item: <item_name>
Price per unit: $ <item_price>
Quantity in stock: <item_stock_quantity>
In stock: <in_stock>
Ratkaisu
Kiitos palautteestasi!