240 likes | 336 Views
What is the resulting value of a?. def g(x): return x ** 2 a = g(4) "4 ** 2" 16 16.0 Nothing gets returned. What is the value of a?. def h(x): print(x * 3) a = h(4.0) "x * 3" "4.0 * 3" 12.0 12 a has no value. What is the value of x?. x = "happy" x = x.split ("y")
E N D
What is the resulting value of a? def g(x): return x ** 2 a = g(4) • "4 ** 2" • 16 • 16.0 • Nothing gets returned
What is the value of a? def h(x): print(x * 3) a = h(4.0) • "x * 3" • "4.0 * 3" • 12.0 • 12 • a has no value
What is the value of x? x = "happy" x = x.split("y") • "happy" • ["happy"] • ["happ"] • ["happ", ""] • ["happ", "y"]
What is the value of x? x = "happy" x = x.split("y") x = "e".join(x) • "happy" • ["happ", ""] • "happe" • ["happ", "e"]
What is the value of x? x = "happy" x = x.split("p") • ["ha", "y"] • ["ha", "p", "y"] • ["ha", "", "y"] • ["hap", "p", "y"]
What is the value of x? x = "happy" x = x.split("p") x.append("fun") x = "p".join(x) • ["ha", "", "y", "fun"] • "hapy fun" • "happy fun" • "happypfun" • "happyfun"
What is the value of x? def add(x, y): x = x + y x = add(3, 5) • 0 • 8 • 3 • 5 • x has no value
What is the value of x? def add(x, y): return return x + y x = add(3, 5) • 0 • 8 • 3 • 5 • x has no value
What does this error mean? z = x + y --- Traceback (most recent call last): File "sandbox.py", line 7, in <module> z = x + y TypeError: Can't convert 'int' object to str implicitly
What does this error mean? b = add(3, 5) --- Traceback (most recent call last): File "sandbox.py", line 1, in <module> b = add(3, 5) NameError: name 'add' is not defined
What does this error mean? c = ",".join(b) --- Traceback (most recent call last): File "sandbox.py", line 8, in <module> c = ",".join(b) TypeError: sequence item 0: expected str instance, int found
What does this error mean? File "sandbox.py", line 4 return ^ IndentationError: expected an indented block
What does this error mean? File "sandbox.py", line 3 def add(x, y) ^ SyntaxError: invalid syntax
What is the value of a? def sum_list(my_list): sum = 0 for i in my_list: sum = sum + i return sum a = sum_list([1, 4, 7]) • 7 • 0 • 12 • 5
What does this error mean? File "sandbox.py", line 4 if a = 5: ^ SyntaxError: invalid syntax
What does this error mean? Traceback (most recent call last): File "sandbox.py", line 2, in <module> "sdfsdf".replace() TypeError: replace() takes at least 2 arguments (0 given)
What is the value of a? def multiply_list(start, stop): product = 1 for element in range(start,\ stop): product = product * element return product a = multiply_list(1, 4) • 24 • 6 • 2 • 1
What does this error mean? Traceback (most recent call last): File "sandbox.py", line 1, in <module> int('a') ValueError: invalid literal for int() with base 10: 'a'
What is the value of x? x = "Hungry hippos" x = x.split("h") • ['Hungry ', 'ippos'] • ['', 'ungry', 'ippos'] • ['', 'ungry', '', 'ippos'] • ['ungry', 'ippos']
Before & After #before a = "1,2,3,4,5,6" #after a = "1, 2, 3, 4, 5, 6"
What is the value of x? x = "I like Ike" x = x.split("I") x = "U".join(x) • I like Ike • U lUkeUke • U like Uke • I luke Ike
Before & After #before a = "i like apples" #after a = "I Like Apples"
Before & After #before: print(a, b) results in: I like #a apples #b #after: print(a, b) results in: I Like Apples
What is the value of x? x = "Happy Happy" x = x.split(" ") x.append("JoyJoy") x = " ".join(x) --- • Happy Happy Joy Joy • HappyHappyJoyJoy • Happy,Happy,Joy,Joy • Happy HappyJoyJoy • HappyHappy Joy Joy