Chapter 3: Data Types and Variables – Assignments

Test your understanding of Python data types and variable usage with the exercises below.

Basic (10 Questions)

  1. Create a variable to store your name, age, and height. Print all three.
  2. Assign an integer value to a variable and print its type using type().
  3. Declare a float variable and a complex variable. Print their values and types.
  4. Store a boolean value in a variable and use it in a conditional statement.
  5. Take two numbers as input and convert them to float before performing division.
  6. Convert a float value to an integer and observe the result.
  7. Use the complex() function to create a complex number and print its real and imaginary parts.
  8. Declare multiple variables in a single line and assign values to them.
  9. Store your city name in a variable and check if it’s of type str.
  10. Use input() to get a number from the user, convert it to int, and print the square of it.

Intermediate (10 Questions)

  1. Write a program to convert boolean values to integers and vice versa.
  2. Take user input of type string and convert it into integer, float, and boolean.
  3. Assign a float value to a variable and round it to the nearest integer.
  4. Use appropriate variable names to store the current year, temperature, and whether it’s raining.
  5. Demonstrate chained assignment with three variables assigned the same value.
  6. Write a program that swaps two numbers using a temporary variable.
  7. Use descriptive variable names to calculate and store the area of a rectangle.
  8. Print the memory address of a variable using id().
  9. Create two variables with the same value. Check if they refer to the same object using is.
  10. Take input from the user and check its data type after converting it to integer.

Advanced (10 Questions)

  1. Write a function that accepts any number and returns its data type.
  2. Simulate a simple data type converter where the user selects a type (int, float, etc.) and provides a value.
  3. Write a program to demonstrate dynamic typing in Python.
  4. Compare the behavior of == and is for strings and integers.
  5. Create a program that stores a user's profile (name, age, email, etc.) using well-named variables and prints it.
  6. Demonstrate implicit and explicit type conversions with examples.
  7. Create variables of each primitive data type and store them in a dictionary. Print the dictionary.
  8. Show how incorrect variable naming can lead to errors. Write an example that fails due to a bad variable name.
  9. Track and display changes to a variable over time using reassignment.
  10. Create a simple CLI tool that prints type, value, and id of any user-entered data.