COMP9021 Principles of Programming


COMP9021 Principles of Programming
Term 1, 2024
Coding Quiz 2
Worth 4 marks and due Week 4 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.
The current code will accept a zero or positive integer (that is, non-strictly negative integer)
with possible leading 0’s and converts it to base 8 (keeping leading 0’s, if any).
Given the following directions:
0: Move North
1: Move North-East
2: Move East
3: Move South-East
4: Move South
5: Move South-West
6: Move West
7: Move North-West
Reading the number written in base 8 from right to left. We start from a position that is the
unique position where the switch is on. Moving to a position switches on to off and off to
on there. By default, all positions are off.
Your program should display the minimal rectangular shape that includes all on positions as
shown in the test cases below.
2
Due Date and Submission
Quiz 1 is due Week 4 Thursday 7 March 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 4 Sunday 10 March 2024 @ 9pm will be
discarded.
Make sure not to change the filename quiz_2.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 2.
Test Cases
$ python3 quiz_2.py
Enter a non-strictly negative integer: 0
Keeping leading 0's, if any, in base 8, 0 reads as 0.

$ python3 quiz_2.py
Enter a non-strictly negative integer: 00
Keeping leading 0's, if any, in base 8, 00 reads as 00.

$ python3 quiz_2.py
Enter a non-strictly negative integer: 0256
Keeping leading 0's, if any, in base 8, 0256 reads as 0400.
3
$ python3 quiz_2.py
Enter a non-strictly negative integer: 032
Keeping leading 0's, if any, in base 8, 032 reads as 040.
$ python3 quiz_2.py
Enter a non-strictly negative integer: 3654
Keeping leading 0's, if any, in base 8, 3654 reads as 7106.

$ python3 quiz_2.py
Enter a non-strictly negative integer: 100738324
Keeping leading 0's, if any, in base 8, 100738324 reads as 600222424.

$ python3 quiz_2.py
Enter a non-strictly negative integer: 73776
Keeping leading 0's, if any, in base 8, 73776 reads as 220060.

$ python3 quiz_2.py
Enter a non-strictly negative integer: 7704322
Keeping leading 0's, if any, in base 8, 7704322 reads as 35307402.

$ python3 quiz_2.py
Enter a non-strictly negative integer: 206537612
Keeping leading 0's, if any, in base 8, 206537612 reads as 1423701614.

$ python3 quiz_2.py
Enter a non-strictly negative integer: 000123456789
Keeping leading 0's, if any, in base 8, 000123456789 reads as 000726746425.
WX:codehelp

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值