# CMU 15-112: Fundamentals of Programming and Computer Science Class Notes: Getting Started

1. Logistics and Preliminaries
2. Running Python
3. Hello World in Python
5. Basic Console Output
6. Importing Modules
7. More Logistics and Preliminaries
8. Syntax, Runtime, and Logical Errors
9. Basic Console Input

1. Logistics and Preliminaries

2. Running Python
Note: Your TA's will be happy to help with any of these steps!

3. Hello World in Python
• Command typed into shell
print("Hello World!")

• File edited in VSCode

print("Hello World!") # This is a comment # print "What will this line do?"

5. Basic Console Output
• Basic print function
print("Carpe") print("diem")

• Print on same line
# You can separate multiple values with commas print("Carpe", "diem") # You can also use end="" to stay on the same line print("Carpe ", end="") print("diem")

• Print using f strings
x = 42 y = 99 # Place variable names in {squiggly braces} to print their values, like so: print(f'Did you know that {x} + {y} is {x+y}?')

6. Importing Modules
• Call without importing
print(math.factorial(20)) # we did not first import the math module # Python output: # NameError: name 'math' is not defined

• Call with importing
import math print(math.factorial(20)) # much better...

7. More Logistics and Preliminaries
• Programming vs Computer Science
• Course Objectives / TP Gallery (see sidebar)

8. Syntax, Runtime, and Logical Errors
• Syntax Errors (Compile-Time Errors)
print("Uh oh!) # ERROR! missing close-quote # Python output: # SyntaxError: EOL while scanning string literal

• Runtime Errors ("Crash")
print(1/0) # ERROR! Division by zero! # Python output: # ZeroDivisionError: integer division or modulo by zero

• Logical Errors (Compiles and Runs, but is Wrong!)
print("2+2=5") # ERROR! Untrue!!! # Python output: # 2+2=5

9. Basic Console Input
• Input a string