3.5. Exercises#
Write a Python function that prints the following:
They'll hibernate during the winter.
Show code cell source
def string_ex1():
print('They\'ll hibernate during the winter.')
print("They'll hibernate during the winter.")
Write a Python function that prints the following:
"Absolutely not," he said.
Show code cell source
def string_ex2():
print('"Absolutely not," he said.')
print("\"Absolutely not,\" he said.")
Write a Python function that prints the following:
"He said, 'Absolutely not,'" recalled Mel.
Show code cell source
def string_ex3():
print("\"He said, 'Absolutely not,'\" recalled Mel.")
Write a Python function that prints the following:
left\right.
Show code cell source
def string_ex4():
print("left\\right")
Write a Python function that prints the following given x = 3:
The rabbit is 3 years old.
Show code cell source
def string_ex5():
x = 3
print(f"The rabbit is {x} years old.")
Write a Python function that prints the following given x = 3 and y = 12.5:
12.5 * 3.
Show code cell source
def string_ex7():
x = 3
y = 12.5
print(f"{x} * {y}.")
Write a Python function that prints the following given x = 3 and y = 12.5:
12.5 * 3 = 37.5
Show code cell source
def string_ex8():
x = 3
y = 12.5
print(f"{x} * {y} = {x*y}.")