Chapter 2 Exercise Set 2: PCEP Practice

Ways to write numbers

  1. Convert each of the following into digit only integers in base 10:

    • 12_345_681

    • 0o12

    • 0O_21

    • 0x12

    • 0X21

  2. Convert the following into base 10 decimal numbers without exponents.

    • 4e2

    • 23e-3

Comparing True and False

Describe and explain the output of the following two statements:

print(True > False)
print(True < False)

Quotes in strings

Write a single line print statement that produces the following output:

"I'm"
""learning to""
''program'' with
"""Python"""

Types of literals

What is the type of each of the following literals?

  1. "Python"

  2. "42"

  3. 42

  4. 42.

  5. False

  6. 'False'

Operators, precedence, and left-sided and right-sided binding

How will the Python interpreter evaluate each of the following expressions?

  1. >>> `print((-3 / 6), (3 / 6), (3 // 6), (-3 // 6))

  2. print((2 % -4), (2 % 4), (2 ** 3 ** 2))

Variables

  1. What two things does every Python variable have?