CS Grade 6-8

CS: Introduction to Python: Variables and Print

Practice storing values and displaying output in Python

View Answer Key
Name:
Date:
Score: / 15

Practice storing values and displaying output in Python

CS - Grade 6-8

Instructions: Read each Python question carefully. Predict the output, write code, or explain the idea in complete sentences.
  1. 1

    What will this Python code display? age = 12 print(age)

  2. 2

    Write one line of Python code that displays the message Hello, Python!

  3. 3

    Write two lines of Python code. First, create a variable named favorite_color and store a color in it. Second, print the variable.

  4. 4

    What will this Python code display? name = "Maya" print("Hi", name)

  5. 5

    What will this Python code display? score = 10 score = score + 5 print(score)

  6. 6
    A storage box with a blank tag holds a colorful object, representing a variable storing information.

    Explain what a variable does in a Python program.

  7. 7

    Fix the error in this code so it displays the message Good morning. message = Good morning print(message)

  8. 8

    Circle or list the valid Python variable names: 2score, score2, first_name, first name, class_count

  9. 9

    What will this Python code display? item = "stickers" count = 4 print(count, item)

  10. 10

    Write Python code that stores the number 7 in a variable named apples and then displays I have 7 apples.

  11. 11
    A shaded grid rectangle with two highlighted sides showing length, width, and area.

    Write a short Python program that stores length = 6 and width = 3, calculates area, and prints the area.

  12. 12

    What will this Python code display? x = 5 y = 2 print(x + y) print("x + y")

  13. 13
    A dog inside a clear storage box with a blank tag, representing a variable value and its name.

    Explain the difference between a variable name and a variable value using this example: pet = "dog".

  14. 14

    Fill in the blanks to create a variable named city with the value Denver and then print it. _____ = "Denver" print(_____)

  15. 15

    Find and fix the problem in this code. Name = "Jordan" print(name)

LivePhysics™.com CS - Grade 6-8

More CS Worksheets

See all CS worksheets

More Grade 6-8 Worksheets

See all Grade 6-8 worksheets