In [20]:
# If you have a list of numbers:
my_list = [1, 5, 2, 3, 9]
# What is the index of the number "3"?
x = 1 # change this line
my_list[x]
Out[20]:
In [21]:
# e.g. How do I use the numpy trigonometric functions?
import numpy as np # you can abbreviate a package import name in order to not use
np.tan(3) # change this function call to get the cosine of 3. Also, does "numpy.tan(3)" work
Out[21]:
In [22]:
from datetime import datetime
class Watch(object):
def __init__(self):
self.stopwatch_timer = 0
def current_time(self):
return str(datetime.now())
w = Watch()
# Write the funciton call that tells the current time on the watch.
In [23]:
x = (3 == '3') # change this line to make x evaluate to True
x
Out[23]:
In [24]:
from datetime import datetime # usually, I would opt to place all the import statements at the top.
useful_info = dict()
# Add the key-value pairs to the useful_info dictionary:
# - 'instructor_name':'Eric Ma'
# - 'date_today':datetime.today()
In [25]:
# Write a function that gives the sum of all numbers up to a passed in number.
# Hint: a for-loop is the easiest implementation.
# Hint: if you're feeling fancy, go ahead and use numpy.
def sum_up_to(x):
"""
Sums up all of the numbers from 1 to x.
"""
###
pass
###
# Then, write another function that uses that function to compute the sums for every even digit up to a number y.
def sums_for_even_digits(y):
"""
Computes the sum_up_to(x) for every even number up to y.
- If y is even, y is included.
- If y is odd, y is not included.
An example function call is as such:
>>> sums_for_even_digits(10)
[0, 3, 10, 21, 36, 55]
"""
### Write your code below.
pass
###
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: