Test your understanding of Python data types and variable usage with the exercises below.
Basic (10 Questions)
- Create a variable to store your name, age, and height. Print all three.
- Assign an integer value to a variable and print its type using
type()
.
- Declare a float variable and a complex variable. Print their values and types.
- Store a boolean value in a variable and use it in a conditional statement.
- Take two numbers as input and convert them to float before performing division.
- Convert a float value to an integer and observe the result.
- Use the
complex()
function to create a complex number and print its real and imaginary parts.
- Declare multiple variables in a single line and assign values to them.
- Store your city name in a variable and check if it’s of type
str
.
- Use
input()
to get a number from the user, convert it to int, and print the square of it.
Intermediate (10 Questions)
- Write a program to convert boolean values to integers and vice versa.
- Take user input of type string and convert it into integer, float, and boolean.
- Assign a float value to a variable and round it to the nearest integer.
- Use appropriate variable names to store the current year, temperature, and whether it’s raining.
- Demonstrate chained assignment with three variables assigned the same value.
- Write a program that swaps two numbers using a temporary variable.
- Use descriptive variable names to calculate and store the area of a rectangle.
- Print the memory address of a variable using
id()
.
- Create two variables with the same value. Check if they refer to the same object using
is
.
- Take input from the user and check its data type after converting it to integer.
Advanced (10 Questions)
- Write a function that accepts any number and returns its data type.
- Simulate a simple data type converter where the user selects a type (int, float, etc.) and provides a value.
- Write a program to demonstrate dynamic typing in Python.
- Compare the behavior of
==
and is
for strings and integers.
- Create a program that stores a user's profile (name, age, email, etc.) using well-named variables and prints it.
- Demonstrate implicit and explicit type conversions with examples.
- Create variables of each primitive data type and store them in a dictionary. Print the dictionary.
- Show how incorrect variable naming can lead to errors. Write an example that fails due to a bad variable name.
- Track and display changes to a variable over time using reassignment.
- Create a simple CLI tool that prints type, value, and id of any user-entered data.