- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Core Tech
Data Types and I/O in Python
In this lab, you will finish a small Python command-line project that teaches variables, arithmetic, data types, conversion, and basic input/output. You will implement the same kinds of examples introduced in the lesson: a rectangle area calculation, int versus float detection, and an age-in-decades calculator that turns user input into formatted output.
Lab Info
Table of Contents
-
Challenge
Explore the starter Python CLI project
Welcome to the lab. You are going to complete a small Python command-line application that closely follows the teaching flow from the lesson: start with variables, perform simple arithmetic, understand
intandfloat, convert between text and numbers, and finally build an interactive age-in-decades script. info> This lab experience was developed by the Pluralsight team using an internally developed AI tool. All sections were verified by human experts for accuracy prior to publications. However, content may still contain errors or inaccuracies, and we recommend independent verification.
To report a problem or provide feedback, click here. Feedback may be used to improve accuracy in accordance with our Privacy Policy. -
Challenge
Use variables and arithmetic
This step focuses on the first ideas introduced in the lesson: variables and arithmetic. Before a program can ask the user for input or print a polished message, it has to store values and compute with them.
-
Challenge
Work with int, float, and conversion
In this step, you will use the rectangle example to introduce Python's numeric data types. This step builds that same bridge by helping the project recognize whole numbers versus decimals and by preparing text input for later math.
-
Challenge
Build the age-in-decades workflow
This step assembles the central program featured in the lesson: the age-in-decades calculator. Up to this point, you have worked on the pieces independently so each concept stayed clear.
-
Challenge
Connect the demo and the script menu
The final step turns the project into a cohesive learning tool. The lesson begins with a shell demonstration and then moves into a longer script, so your finished application should support both experiences. ### Run the Application
Now that you've completed all of the functions, it's time to run the program and verify that everything works together.
In the Terminal tab, run the application:
python3 main.pyYou should see a menu similar to:
Python Foundations Demo 1. Shell-style variables and types demo 2. Age in decades calculator Choose an option:Test both menu options:
- Enter
1to view the variables, calculations, and type demonstrations. - Enter
2to calculate an age in decades and remaining years.- Try a few different inputs:
- A valid age, such as
42 - An age with surrounding spaces, such as
42 - An invalid value, such as
abc - A negative age, such as
-5
- A valid age, such as
- Try a few different inputs:
Confirm that: The shell demo displays the rectangle information and type examples. The age calculator displays the correct decades and remaining years.
Invalid input shows the message:
Please enter a whole number age.If everything works as expected, you've successfully completed the Python Foundations demo project and connected all of the helper functions into a working application.
- Enter
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.