This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define a function called join_strings accepts an argument called words. It will be a list. | |
| # Inside the function, create a variable called result and set it to "", an empty string. | |
| # Iterate through the words list and append each word to result. | |
| # Finally, return the result. | |
| # Don't add spaces between the joined strings! | |
| n = ["Michael", "Lieberman"] | |
| def join_strings(words): | |
| result = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The Python range() function is just a shortcut for generating a list, so you can use ranges in all | |
| # the same places you can use lists. | |
| range(6) # => [0,1,2,3,4,5] | |
| range(1,6) # => [1,2,3,4,5] | |
| range(1,6,3) # => [1,4] | |
| # The range function has three different versions: | |
| range(stop) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define a function called print_list that has one argument called x. | |
| # Inside that function, print out each element one by one. | |
| # Then call your function with the argument n. | |
| n = [3, 5, 7] | |
| def print_list(x): | |
| for i in range(0, len(x)): | |
| print x[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add 3 to the item at index one of the list. | |
| # Store the result back into index one. | |
| # Return the list. | |
| def list_function(x): | |
| x[1] = x[1] + 3 | |
| return x | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # You pass a list to a function the same way you pass any other argument to a function. | |
| def list_function(x): | |
| return x | |
| n = [3, 5, 7] | |
| print list_function(n) | |
| # list_function returns only the item stored in index one of x, rather than the entire x list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Write a function called string_function that takes in a string argument (s) and then | |
| # returns that argument concatenated with the word 'world'. Don't add a space before word! | |
| n = "Hello" | |
| def string_function(s): | |
| return s + "world" | |
| print string_function(n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ####################### | |
| # Appending to a list # | |
| ####################### | |
| n = [1, 3, 5] | |
| # Append the number 4 to the end of the list n. | |
| n.append(4) | |
| print n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##################### | |
| # List accessing #### | |
| ##################### | |
| # Please add the code to print out the second element in the list. | |
| n = [1, 3, 5] | |
| print n[1] | |
| ############################# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lloyd = { | |
| "name": "Lloyd", | |
| "homework": [90.0, 97.0, 75.0, 92.0], | |
| "quizzes": [88.0, 40.0, 94.0], | |
| "tests": [75.0, 90.0] | |
| } | |
| alice = { | |
| "name": "Alice", | |
| "homework": [100.0, 92.0, 98.0, 100.0], | |
| "quizzes": [82.0, 83.0, 91.0], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lloyd = { | |
| "name": "Lloyd", | |
| "homework": [90.0, 97.0, 75.0, 92.0], | |
| "quizzes": [88.0, 40.0, 94.0], | |
| "tests": [75.0, 90.0] | |
| } | |
| alice = { | |
| "name": "Alice", | |
| "homework": [100.0, 92.0, 98.0, 100.0], | |
| "quizzes": [82.0, 83.0, 91.0], |
NewerOlder