id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

david.white@denison.edu cs111fall2019 > diagonal2
prev  |  next  |  chance

Write a function that takes an integer n as a parameter, and returns an n × n grid (list of lists) in which all cells on and below the main diagonal contain a 1 and the rest of the cells contain a 0. For example, if n = 5, your function should return the grid

[[1, 0, 0, 0, 0],
[1, 1, 0, 0, 0],
[1, 1, 1, 0, 0],
[1, 1, 1, 1, 0],
[1, 1, 1, 1, 1]]

diagonal2(3) → [[1, 0, 0], [1, 1, 0], [1, 1, 1]]
diagonal2(2) → [[1, 0], [1, 1]]
diagonal2(5) → [[1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 1, 1, 0], [1, 1, 1, 1, 1]]

...Save, Compile, Run (ctrl-enter)

def diagonal2(n):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Copyright Nick Parlante 2017 - privacy