0% found this document useful (0 votes)
3 views4 pages

Assignment 4

This document outlines Assignment 4 for the BANA3020 Introduction to Programming course, due on November 20th, 2024. It includes three problems: matrix multiplication using nested loops, creating a list of divisors, and summing elements in a nested list, along with specific submission instructions and requirements for coding practices. Students are required to submit their work in a specified format and are reminded of the importance of academic honesty.

Uploaded by

123minhcchau123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Assignment 4

This document outlines Assignment 4 for the BANA3020 Introduction to Programming course, due on November 20th, 2024. It includes three problems: matrix multiplication using nested loops, creating a list of divisors, and summing elements in a nested list, along with specific submission instructions and requirements for coding practices. Students are required to submit their work in a specified format and are reminded of the importance of academic honesty.

Uploaded by

123minhcchau123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment 4

BANA3020 Introduction to Programming Fall 2024 – Assignment 4

Assignment Submission Instructions:

• Due date: Nov 20th, 2024


• Your program should work correctly on all inputs. If there are any specifications about
how the program should be written (or how the output should appear), those specifications
should be followed.
• Your code and functions/modules should be appropriately commented. However, try to
avoid making your code overly busy (e.g., include a comment on every line).
• Variables and functions should have meaningful names, and code should be organized
into functions/methods where appropriate.
• Academic honesty is required in all work you submit to be graded. You MUST NOT copy
or share your code with other students to avoid plagiarism issues.
• Use the template provided to prepare your solutions.
• Upload your work to Canvas as a .py file.
• Submit separate .py file for each problem with the following naming format: Assign-
ment1_Q1.py. Failure to submit a .py file for lab or assignment will result in a 0. Note: If
you are working on Jupiter Notebook, you need to download/convert it to Python .py file
for submission.
• Late submission of an assignment without an approved extension is NOT allowed.

Assignment № 4 Page 1
Problem 1 – Matrix multiplication using Nested Loops 40pts

A matrix is a mathematical object defined as a 2-dimensional array arranged in rows and columns.
In Python, a matrix is usually represented as a 2-D list. For example the following matrix A has
dimension 3x3:

 
12 7 3
 
A=
 4 5 6 

7 8 9

can be represented in Python as:


A = [[12, 7, 3], [4, 5, 6], [7, 8, 9]]
A vector is a special matrix where the number of rows (columns) is 1. The following vector b
has dimension 3x1:
 
1
 
b=
2

3

which can be represented in Python as:


b = [[1], [2], [3]]
Keep in mind that, here we use a nested list to store b, which is not the optimal way to do
so. Matrix-vector multiplication is a very common operation in data science/machine learning.
Here’s how the multiplication of a matrix A of dimension n x m and a vector b of dimension m x
1 goes:

1. Number of columns of matrix A should match number of rows of vector b.

2. The result of the operation is a vector c of dimension n x 1.

3. The entries in vector c can be calculated as followings:

     
12 7 3 b1 a11 ∗ b1 + a12 ∗ b2 + a13 ∗ b3
     
A=
 4 5 6  b = b2  c = a21 ∗ b1 + a22 ∗ b2 + a23 ∗ b3 
    
7 8 9 b3 a31 ∗ b1 + a32 ∗ b2 + a33 ∗ b3

Your code should work for any matrix A,b of any appropriate dimensions stored in Python list as
described above. For example:
     
12 7 3 1 35
     
 4 5 6 b = 2 c = 32
     
7 8 9 3 50

Problem 2 - Create a list of divisor 30pts

In this exercise, you are going to use the library random and the function randint that ouputs a
random number between a and b:

Assignment № 4 Page 2
1 import random
2 random_integer = random . randint (a , b )

Write a Python script that perform the following tasks:

1. Input a number N from the keyboard using function input.

2. Input a large number large_num from the keyboard using function input.

3. Create a list of N random numbers between 1 and large_num.

4. Create a list of size N, each component is a list that contains all the divisors of the numbers
in the list above.

Example:

1 Enter a number N :3
2 Enter a large number :20
3 integer_list
4 Out [172]: [1 , 18 , 8]
5 integer_divisor
6 Out [175]: [[1] , [1 , 2 , 3 , 6 , 9 , 18] , [1 , 2 , 4 , 8]]

Assignment № 4 Page 3
Problem 3 - Sum of elements in nested list 30pts

Write a Python script that performs the following:

1. Input is a nested list of numbers. For example:

1 my_list =[[1] , [1 , 2 , 3 , 6 , 9 , 18] , [1 , 2 , 4 , 8]]

2. Compute the sum of the numbers in each of the component list, store these sums in a list.

1 list_sum
2 Out [187]: [1 , 39 , 15]

Required format to Canvas

"""
VinUniversity
BANA3020 - Fall 2023 - Introduction to Programming
Lab [ x ] - Week [ y ] - [ topic ]
by your name ( Student ID )

Date : Oct . 17 , 2023


Disclaimer : I certify that this assignment is my own work and that I ←-
have not copied in part or whole or otherwise plagiarised the work ←-
of other students and / or persons .
"""

"""
# - - - - - - - - - - - - - - - - - - - - - - - Problem 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# A short description of the problem . For example : Write a
# program that prints out " Hello , World !"
#----------------------------------------------------------------

"""

Assignment № 4 Page 4

You might also like