1 / 24

What is the resulting value of a?

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")

nancy
Download Presentation

What is the resulting value of a?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What is the resulting value of a? def g(x): return x ** 2 a = g(4) • "4 ** 2" • 16 • 16.0 • Nothing gets returned

  2. 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

  3. What is the value of x? x = "happy" x = x.split("y") • "happy" • ["happy"] • ["happ"] • ["happ", ""] • ["happ", "y"]

  4. What is the value of x? x = "happy" x = x.split("y") x = "e".join(x) • "happy" • ["happ", ""] • "happe" • ["happ", "e"]

  5. What is the value of x? x = "happy" x = x.split("p") • ["ha", "y"] • ["ha", "p", "y"] • ["ha", "", "y"] • ["hap", "p", "y"]

  6. 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"

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. What does this error mean? File "sandbox.py", line 4 return ^ IndentationError: expected an indented block

  13. What does this error mean? File "sandbox.py", line 3 def add(x, y) ^ SyntaxError: invalid syntax

  14. 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

  15. What does this error mean? File "sandbox.py", line 4 if a = 5: ^ SyntaxError: invalid syntax

  16. 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)

  17. 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

  18. 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'

  19. What is the value of x? x = "Hungry hippos" x = x.split("h") • ['Hungry ', 'ippos'] • ['', 'ungry', 'ippos'] • ['', 'ungry', '', 'ippos'] • ['ungry', 'ippos']

  20. Before & After #before a = "1,2,3,4,5,6" #after a = "1, 2, 3, 4, 5, 6"

  21. 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

  22. Before & After #before a = "i like apples" #after a = "I Like Apples"

  23. Before & After #before: print(a, b) results in: I like #a apples #b #after: print(a, b) results in: I Like Apples

  24. 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

More Related