Skip to content

Commit 6beb37a

Browse files
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.
1 parent 478f4df commit 6beb37a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

100+ Python challenging programming exercises.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,5 +2371,40 @@ solutions=solve(numheads,numlegs)
23712371
print solutions
23722372

23732373
#----------------------------------------#
2374+
Level: Easy
2375+
Question:
2376+
Create a NxN mutiplication table, of size
2377+
provided in parameter. (Credit: CodeWars)
2378+
2379+
Example:
2380+
input: 3
2381+
Output:
2382+
1 2 3
2383+
2 4 6
2384+
3 6 9
2385+
Returned value:
2386+
[[1,2,3][2,4,6][3,6,9]]
2387+
2388+
Hint:
2389+
Double loop to create mutiple arrays.
2390+
2391+
Solution one (simplified):
2392+
2393+
def mutiplication_table(size: int) -> list:
2394+
return [[rows * cols for rows in range(1,size+1)] for cols in range(1,size+1)]
2395+
2396+
Solution two (traditional):
2397+
2398+
def mutiplication_table(size: int) -> list:
2399+
temp = []
2400+
for rows in range(1,size+1):
2401+
col = []
2402+
for cols in range(1,size+1):
2403+
col.append(rows*cols)
2404+
temp.append(col)
2405+
return temp
2406+
2407+
#----------------------------------------#
2408+
23742409

23752410

0 commit comments

Comments
 (0)