Daily Data Science Puzzle
import numpy as np
# save $122.50 per month
x = 122.5
net_wealth = np.arange(0, 1000, x)
# how long to save >$1000?
What is the output of this puzzle?
Numpy is a popular Python library for data science focusing on linear algebra.
This puzzle is about the numpy arange function. The arange function is everywhere in data science.
You might know the Python built-in
range(x,y,z) function that creates a sequence of linear progressing values. The sequence starts from x, increases the values linearly by y, and ends if the value becomes larger than z.
arange(x,y,z) function is similar but creates a numpy array and works with float numbers as well.
Note that a common mistake in this puzzle is to not account for the first value of the array: 0.
Are you a master coder?
Test your skills now!
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.