1.7 Practice

Working with Variables

Answer the following questions using Python.

  1. Create 5 variables with the following names and types then print each in the console:

    • name as a string
    • age as an integer
    • grade: float
    • is_student: boolean
    • favorite_color: string
  2. Reassign each variable to the same value, but this time use type hinting to declare the data type of each variable.

  3. Reassign the name variable the same name but in all uppercase letters using a string method. Print the new value of name in the console.

  4. Add the age variable to the grade variable. What is the data type of the result? Print the type of the output to the console using the built-in type function.

  5. Create a dictionary named person that includes each variable you created in step 2 as a key and its value as the value. Print the dictionary in the console.

  6. Use an f-string to print a sentence that includes the name, age, and favorite_color keys from the person dictionary. It should follow this pattern: “My name is [name]. I am [age] years old. My favorite color is [favorite_color]. I will get a [grade] in this class.”