Exercises

3.5. Exercises#

  1. Write a Python function that prints the following:

They'll hibernate during the winter.
Hide code cell source
def string_ex1():
    print('They\'ll hibernate during the winter.')
    print("They'll hibernate during the winter.")
  1. Write a Python function that prints the following:

"Absolutely not," he said.
Hide code cell source
def string_ex2():
    print('"Absolutely not," he said.')
    print("\"Absolutely not,\" he said.")
  1. Write a Python function that prints the following:

"He said, 'Absolutely not,'" recalled Mel.
Hide code cell source
def string_ex3():
    print("\"He said, 'Absolutely not,'\" recalled Mel.")
  1. Write a Python function that prints the following:

left\right.
Hide code cell source
def string_ex4():
    print("left\\right")
  1. Write a Python function that prints the following given x = 3:

The rabbit is 3 years old.
Hide code cell source
def string_ex5():
    x = 3
    print(f"The rabbit is {x} years old.")
  1. Write a Python function that prints the following given x = 3 and y = 12.5:

12.5 * 3.
Hide code cell source
def string_ex7():
    x = 3
    y = 12.5
    print(f"{x} * {y}.")
  1. Write a Python function that prints the following given x = 3 and y = 12.5:

12.5 * 3 = 37.5
Hide code cell source
def string_ex8():
    x = 3
    y = 12.5
    print(f"{x} * {y} = {x*y}.")