Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New challenge: Multiplication table #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 100+ Python challenging programming exercises.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2371,5 +2371,40 @@ solutions=solve(numheads,numlegs)
print solutions

#----------------------------------------#
Level: Easy
Question:
Create a NxN mutiplication table, of size
provided in parameter. (Credit: CodeWars)

Example:
input: 3
Output:
1 2 3
2 4 6
3 6 9
Returned value:
[[1,2,3][2,4,6][3,6,9]]

Hint:
Double loop to create mutiple arrays.

Solution one (simplified):

def mutiplication_table(size: int) -> list:
return [[rows * cols for rows in range(1,size+1)] for cols in range(1,size+1)]

Solution two (traditional):

def mutiplication_table(size: int) -> list:
temp = []
for rows in range(1,size+1):
col = []
for cols in range(1,size+1):
col.append(rows*cols)
temp.append(col)
return temp

#----------------------------------------#