What is the difference between a method and a function?
In [ ]:
Convert the below variable to a string and assign to string_var
. Assign the length of that string to: len_var
In [1]:
initial_var = 358645317684531432678
What do we mean when we say local
scope?
What will the output of the code below be? Highlight the line numbers where the scope changes.
In [2]:
name = "Oi, you there"
def update_name():
name = "what?"
print(name)
update_name()
print(name)
In [ ]:
What would change if you added the line global name
into the function update_name
?
In [ ]:
Write a script below that asks a user for 2 numbers, these will not be integers by default. Pass those numbers to a function, called power
, that returns the first argument to the power of the second. You will need to look up the symbol for to the power of
in the Python docs
In [4]:
num_one = None
num_two = None
def power(one, two):
pass
In [ ]:
from nose.tools import assert_equal, assert_not_equal
assert_equal(square(12,2), 144)
assert_equal(square(50, 4), 6250000)
assert_equal(square(2,2), 4)