Session 2 Assessment - Google Forms
Session 2 Assessment - Google Forms
Session 2 Assessment - Google Forms
1. Effort counts more than the answer. Make sure you comment your code to explain
what you are doing
2. This assignment is a series of questions that help you finally build one large chunk of
code that does something cool :). At each stage, make sure to copy your code into a
new cell so I can follow your progress.
3. Make sure that your email and phone number are the same ones that you provided
while registering.
4. Have fun! This assignment is meant to keep you interested in the topic. Remember
that we'll be covering a lot more in the following lectures.
5. The deadline for this assignment is Sunday, 23 June
GeeksForGeeks - https://www.geeksforgeeks.org/python-programming-language-
tutorial/
W3Schools - https://www.w3schools.com/python/default.asp
FreeCodeCamp - https://www.freecodecamp.org/news/learning-python-from-zero-to-
hero-120ea540b567 (My personal favourite)
And of course, the Python Docs - https://docs.python.org/3/tutorial/introduction.html
1. Email *
2. Name *
3. Email *
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 1/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
4. Phone Number *
5. 1. Identity Matrix
Before we start with the main project question, do make sure to try out the identity matrix
question from the session that we skipped. Write a function that takes a parameter N
denoting the matrix size, and return an NxN identity matrix. Note, that this is optional to
attempt, but I would highly recommend you give it a try. Submit the link to your Colab
notebook (make sure it's publicly viewable).
2. Quiz Questions
In this project, we will be attempting to write code that performs vector operations. After each
question, make sure to copy your code into a new cell so that I can follow your progress, and see
if, and where you got stuck. At the end of this assignment, you should have a program that is
capable of doing arithmetic on matrices!
Then, allow the user to input a number. If the number is from 1-7, then print the option. If the
number is 8, exit the loop. If the number is anything else, print an error message - "Invalid Choice!",
and continue.
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 2/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
Sample Output:
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 3/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 4/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
Note: For all examples from now on, we shall assume that A is [1, 2, 3, 4, 5, 5, 4, 3, 2, 1] and B is [-1,
1, 0, 2, 1, 3, 2, 4, 3, 5].
Hint: Take a look at the split() method to generate lists. Also, remember that inputs are strings,
and we need integers.
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 5/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
Sample Output
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 6/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
Sample Output
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 7/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 8/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
Sample Output
6. Going Further
We've made a basic vector arithmetic calculator. Congratulations! Give yourself a pat on the back
and feel free to play around with it.
Now, how can we improve this calculator? Right now, it only works in 10-dimensional space. Could
you add an option that sets the number of dimensions to be used for all vectors? Keep in mind
that, if in the middle of the program, the number of dimensions is changed, then vectors A and B
must be reset to some default value of the specified dimensions. Good luck!
6. Provide the link to your Google Colab notebook here. Make sure it's publicly *
viewable.
NumPy Section
For the following questions, submit your Google Colab links (make sure they're publicly viewable)
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 9/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
7. 1. Create a 2D array of shape (5,5) with values ranging from 1 to 50 with a step of *
2. Find the sum of all numbers in this array. Find the cumulative sum of the array.
Then find the cumulative sum along axis = 1.
8. 2. Create two 3x3 matrices with positive integers of your choice. Perform matrix *
addition and multiplication of the two matrices. After that give transpose of each of
the matrices.
9. 3. Create a 3D array of shape (2, 3, 4) with random integers between 1 and 20. *
Slice to get a subarray of shape (2, 2, 2) from the first two rows and first two
columns of each 2D array, then reshape the subarray into a 2x4 matrix. Calculate
mean, variance, and standard deviation of the resulting matrix.
10. 4. Create a user defined function (a function that the coder created by himself) *
and take in a user defined input: a Numpy array called *height*.
*height* is a one dimensional array height of length n. There are n vertical lines
drawn such that the two endpoints of the ith line are (i,0) and (i,height[i]).
Find two lines that together with the x axis form a container, such that the
container contains the most water.
Return the maximum amount of water a container can store.
Note you may not slant the container
Forms
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 10/11
6/25/24, 4:17 PM Session 2 Assessment - Fundamentals of Python and NumPy
https://docs.google.com/forms/d/17DHfyUvJF-7R34IIYQI8CZm9BL17EDlNBk03qRjGOfU/edit 11/11