Tuesday, June 18, 2013
Python June 18, 2013
Hello Readers,
# Exercise 0 : List Access
"""
Please add the code to print out the second element in the list.
"""
n = [1, 3, 5
]
# Add your code below
print n[1]
# Exercise 1 : List Element Modification
"""
Go ahead and multiply the second element of the n list by 5. Print out the result
"""
n = n[1] * 5
print n
# Exercise 2 : Appending to a list
"""
Append the number 4 to the end of the list n.
"""
n.append(4)
# Exercise 3 : Removing elements from lists
"""
Remove the first item from the list n using either .pop(), .remove(), or del.
"""
del(n[0])
"""
Learning Python
Lesson 7 : Lists & Functions
Reviewing Functions
Simple programming exercises from Codecademy
"""
# Exercise 0 : Changing Functionality
"""
Change the function so the given argument is multiplied by 3 and returned.
"""
number = 5
def my_function(x):
return x*3
print my_function(number)
# Exercise 1 : Multiple Arguments
"""
Create a variable called m and set it equal to 5
Create a variable called n and set it equal to 13
Define a function called add_function that takes 2 arguments and adds them together.
The function should return the result
Call your add_function and give it m and n. Print the result like this:
print add_function(m,n)
"""
m = 5
n = 13
def add_function(m, n):
return m + n
print add_function(m,n)
# Exercise 2 : String Functions
"""
Create a variable called first and set it equal to "Hello"
Write a function called string_function that takes in a
string argument and then concatenates it the word 'world'.
Return the result.
Call your string_function and give it first. Print the result.
"""
first = "Hello"
def string_function(word):
return first
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment