From 6beb37a9f38ba40e409e1539815d0055f0723885 Mon Sep 17 00:00:00 2001 From: Rohit Barua <83600150+Rohit-beep-droid@users.noreply.github.com> Date: Wed, 9 Jun 2021 23:30:14 -0400 Subject: [PATCH] Update 100+ Python challenging programming exercises.txt Added a simple multiplication table problem, which is very beginner friendly since it requires them to think about the use of multiple for loops, range() function, and most importantly how to create/work with multiple dimension arrays on Python. --- ...thon challenging programming exercises.txt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index 97af5aaf..67c58889 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -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 + +#----------------------------------------# +