Joseph Haugh
University of New Mexico
jhaugh
as your “guru”
jhaugh
print()
function or the input()
functionprint
a string
argument it simply prints that stringprint
a variable
argument it looks at the value inside and prints thatprint
may be called with more than 1 argumentprint
with multiple arguments prints each argument and separates each with a space in the outputOUTPUT
5 6 !
min
function takes in any amount of numbers as arguments and returns the minimummax
function takes in any amount of numbers as arguments and returns the maximumCODE
x = 5
y = 50
z = 500
print(min(x, y, z))
print(max(x, y, z))
print(min(x, y, z, 1))
print(max(x, y, z, 1000))
OUTPUT
5
500
1
1000
CODE
max()
MISTAKE
Not enough arguments
OUTPUT
TypeError: max expected 1 arguments, got 0
max(3, 5
Forgot closing paren )
SyntaxError: unexpected EOF while parsing (
max(3, x)
Forgot to define variable x
NameError: name ‘x’ is not defined
newline
, a tab
, or even just a quoteprint("Hello\nWorld") # Prints Hello World on two separate lines
print("Hello\tWorld") # Prints Hello World with a tab between
print("\"Hello World\"") # Prints "Hello World"
Take the remaining time to complete all of the exercises in chapters 2 & 3
Comments
Visualize