Chapter 2 Lab Notes
Chapter 2 Lab Notes
Print Literals
To print a literal, you simply pass it to the print() function
print(5) # Output: 5
print(“Hello”) # Output: Hello
print(True) # Output: True
String Literals
You can use single or double quotes for string literals:
print(‘Single quotes’)
print(“Double quotes”)
Escape Sequence
Escape sequences allow you to include special characters in string literals (begin
with backslash):
print(“Hello\nWorld”) # Output: Hello
# World
number1 = 20
number2 = 5
number3 = 17
height1 = 9
height2 = 9
width1 = 19.5
width2 = 20.0
# Calculate celsius.
celsius = (fahrenheit - 32) * (5/9)
# Output.
print(f"Fahrenheit temperature: {fahrenheit:.2f}") # Two digits past the decimal
point
print(f"Celsius temperature: {celsius:.2f}")