COMP9021 Principles of Programming


COMP9021 Principles of Programming 
Term 2, 2024 
Coding Quiz 5 
Worth 4 marks and due Week 8 Thursday @ 9pm 
 
Description 
You are provided with a stub in which you need to insert your code where indicated without doing any 
changes to the existing code to complete the task. Although it is not needed for this quiz, you may import 
any extra module that is already installed in Ed if you wish. 
The program randomly generates a grid with 0s and 1s, whose dimension is controlled by user input, as 
well as the density of 1s in the grid, and finds out for a given step_number ≥ 1 and a given step_size ≥ 2, 
the number of stairs of step_number many steps, with all steps of size step_size. 
A stair of 1 step of size 2 is of the form: 
1 1 
 1 1 
A stair of 2 steps of size 2 is of the form 
1 1 
 1 1 
 1 1 
A stair of 1 step of size 3 is of the form 
1 1 1 
 1 
 1 1 1 
A stair of 2 steps of size 3 is of the form 
1 1 1 
 1 
 1 1 1 
 1 
 1 1 1 
 2 
 
 
The output lists the number of stairs from smallest step sizes to largest step sizes, and for a given step size, 
from stairs with the smallest number of steps to stairs with the largest number of stairs. 
Your task is to implement the function called stairs_in_grid(). 
You may possibly define other functions. 
The provided stub and the outputs of the sample test cases explain the task to be performed. 
 
Marking 
 stairs_in_grid() 4 marks 
 ------------------------------------ 
 Total 4 marks 
 
 
Due Date and Submission 
Quiz 5 is due Week 8 Thursday 18 July 2024 @ 9.00pm (Sydney time). 
Note that late submission with 5% penalty per day is allowed up to 3 days from the due date, that is, any 
late submission after Week 8 Sunday 21 July 2024 @ 9pm will be discarded. 
Make sure not to change the filename quiz_5.py while submitting by clicking on [Mark] button in Ed. 
It is your responsibility to check that your submission did go through properly using Submissions link in Ed 
otherwise your mark will be zero for Quiz 5. 
 
 3 
 
 
Test Cases 
 
$ python quiz_5.py 
Enter three positive integers: 0 1 2 
Here is the grid that has been generated: 
 1 1 
 0 1 
 
 
$ python quiz_5.py 
Enter three positive integers: 0 1 3 
Here is the grid that has been generated: 
 1 1 0 
 1 1 1 
 1 1 1 
 
For steps of size 2, we have: 
 2 stairs with 1 step 
 
 
$ python quiz_5.py 
Enter three positive integers: 0 3 9 
Here is the grid that has been generated: 
 1 1 0 1 1 1 1 1 1 
 1 1 1 1 0 1 1 1 0 
 0 1 1 0 1 1 1 1 1 
 1 1 0 0 0 1 0 1 1 
 1 1 0 1 1 1 1 1 0 
 0 1 1 0 1 1 0 1 1 
 1 1 0 1 1 1 1 1 1 
 1 0 1 1 0 0 1 1 0 
 0 1 1 1 1 1 1 1 1 
 
For steps of size 2, we have: 
 5 stairs with 1 step 
 1 stair with 2 steps 
 1 stair with 3 steps 
 1 stair with 4 steps 
 
For steps of size 3, we have: 
 4 stairs with 1 step 
 
 4 
 
 
$ python quiz_5.py 
Enter three positive integers: 0 3 7 
Here is the grid that has been generated: 
 1 1 0 1 1 1 1 
 1 1 1 1 1 1 0 
 1 1 1 0 0 1 1 
 0 1 1 1 1 1 1 
 1 0 0 0 1 0 1 
 1 1 1 0 1 1 1 
 1 1 0 0 1 1 0 
 
For steps of size 2, we have: 
 2 stairs with 1 step 
 2 stairs with 2 steps 
 
For steps of size 3, we have: 
 1 stair with 2 steps 
 
 
$ python quiz_5.py 
Enter three positive integers: 0 4 8 
Here is the grid that has been generated: 
 1 1 0 1 1 1 1 1 
 1 1 1 1 1 1 1 1 
 0 1 1 1 1 1 1 0 
 0 1 1 1 0 1 1 1 
 1 1 1 1 1 1 1 0 
 1 0 0 1 0 1 1 1 
 1 1 0 1 1 1 1 1 
 1 1 0 0 1 1 1 0 
 
For steps of size 2, we have: 
 7 stairs with 1 step 
 3 stairs with 2 steps 
 2 stairs with 3 steps 
 
For steps of size 3, we have: 
 2 stairs with 1 step 
 1 stair with 2 steps 
 
For steps of size 4, we have: 
 1 stair with 1 step 
 
 5 
 
 
$ python quiz_5.py 
Enter three positive integers: 0 5 9 
Here is the grid that has been generated: 
 1 1 0 1 1 1 1 1 1 
 1 1 1 1 1 1 1 0 1 
 1 1 1 1 1 1 0 1 0 
 1 1 1 1 0 1 1 1 1 
 1 1 1 1 1 1 1 0 1 
 0 0 1 1 1 1 1 0 1 
 1 1 1 1 1 1 0 1 1 
 1 1 1 1 1 0 0 1 1 
 1 0 1 1 1 1 0 1 1 
 
For steps of size 2, we have: 
 4 stairs with 1 step 
 5 stairs with 2 steps 
 1 stair with 3 steps 
 2 stairs with 4 steps 
 
For steps of size 3, we have: 
 9 stairs with 1 step 
 
For steps of size 4, we have: 
 2 stairs with 1 step 
 
 
 6 
 
 
Some Test Cases Explained 
 
$ python quiz_5.py 
Enter three positive integers: 0 1 3 
Here is the grid that has been generated: 
 1 1 0 
 1 1 1 
 1 1 1 
 
For steps of size 2, we have: 
 2 stairs with 1 step 
$ python quiz_5.py 
Enter three positive integers: 0 3 9 
Here is the grid that has been generated: 
 

  • 10
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值