Given a list of inventory items and a specific item, write a function that will either print "We have _ in stock!" or "We are out of _" for that item.
Here is a list of inventory:
inventory = ['pens', 'paper', 'staples', 'paperclips', 'tape', 'crayons', 'highlighters']
>>> do_we_have('staples')
We have staples in stock!
>>> do_we_have('paper')
We have paper in stock!
>>> do_we_have('pencils')
We are out of pencils
You can use the "in" operator to check if an item is in a list:
>>> 0 in [1, 2, 3]
False
>>> 1 in [1, 2, 3]
True
%pylab inline
x = np.mean(imread("data/puzzle.png"), axis=-1)
imshow(x, cmap=cm.gray)
For this exercise please download the following image "puzzle.png". Note that the file "puzzle.png" would need to be in the same folder as the notebook you are working in (named "[…].ipynb", where […] is the title you put at the top of the notebook). If you put the file "puzzle.png" in a folder called "data", as I did, you would need to refer to it as "data/puzzle.png".
This image contains 4 sections of 300 x 300 pixels which I cut out of a 600 by 600 pixel image. You can load the image as an array of pixel values by the following command:
x = np.mean(imread("puzzle.png"), axis=-1)
The array x is now a 300 by 1200 pixel array. You can and should test that by running x.shape. You can and should also plot the image with
imshow(x, cmap=cm.gray)
Where x is the array that you would like to turn into an image and cmap=cm.gray tells the imshow function to interpret the image as a gray scale image. If you leave out the second argument, imshow will plot the image on a scale from red to blue instead of white to black. Try it out!
Your job is to solve the puzzle by turning the 300 by 1200 image "puzzle.png" into a 600 by 600 image "solution.png"such that the poor chopped up animal is whole again.
You need to define at least one new array for the solution image (you can use more helper arrays if you want). You can use the function np.full() to create an array y of shape (600,600) which is filled with any value, e.g. 0.
Once you solved the puzzle you can save your array y as an image with the name "solution.png" with the following command:
imsave("solution.png", y, cmap=cm.gray)
You can also assign to pieces of arrays:
>>> big_array = array([1,2,3,4,5,6,7,8,9,10])
>>> piece = array([100, 200])
>>> big_array[:2] = piece
>>> print(big_array)
[100 200 3 4 5 6 7 8 9 10]
Write a function that takes in a person's name, and does one of three things:
_! Is that your full name?"_! That's a lovely name!"_! Can I call you [X]?" Where [X] is the first three characters of the person's name.>>> greeter("Katy")
Hello Katy! Is that your full name?
>>> greeter("Manuel")
Hello Manuel! That's a lovely name!
>>> greeter("Wendell")
Hello Wendell! That's a lovely name!
>>> greeter("Wendell Smith")
Hello Wendell Smith! Can I call you Wen?
>>> greeter("Katy Krueger")
Hello Katy Krueger! Can I call you Kat?
If you get stuck, you may want to do an internet search for "python string concatenation" or "python if statement".