COMP9021 -无代写
时间:2024-07-10
1

COMP9021 Principles of Programming
Term 2, 2024
Coding Quiz 4
Worth 4 marks and due Week 7 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.
Your task is to implement two (2) functions called is_good_prime() and smallest_good_prime().
A number is said to be a "good" prime if it is prime and consists of nothing but distinct nonzero digits.
The function is_good_prime() returns True or False depending on whether the integer called number
provided as argument is or is not a good prime, respectively. The function will be tested with a positive
integer at most equal to 10_000_000.
The function smallest_good_prime() takes a nonempty string argument called pattern consisting of digits
and question marks (‘?’) of length at most 7 (which does not need to be checked). Question marks must
be replaced by digits so that the resulting number is the smallest good prime, in case it exists. The function
smallest_good_prime() returns that number if it exists, None otherwise.
You may possibly define other functions.
The provided stub and the outputs of the sample test cases explain the task to be performed.

Marking
is_good_prime() 1.5 marks
smallest_good_prime() 2.5 marks
--------------------------------------------------
Total 4.0 marks

Due Date and Submission
Quiz 4 is due Week 7 Thursday 11 July 2024 @ 9.00pm (Sydney time).


2

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 7 Sunday 14 July 2024 @ 9pm will be discarded.
Make sure not to change the filename quiz_4.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 4.

Test Cases

$ python
...
>>> from quiz_4 import *
>>> is_good_prime(867)
False
>>> is_good_prime(4027)
False
>>> is_good_prime(12923)
False
>>> is_good_prime(16879)
True
>>> is_good_prime(26317)
True
>>> smallest_good_prime('?0?')
>>> smallest_good_prime('2?2')
>>> smallest_good_prime('123')
>>> smallest_good_prime('?98')
>>> smallest_good_prime('3167')
3167
>>> smallest_good_prime('??')
13
>>> smallest_good_prime('???')
127
>>> smallest_good_prime('1?7')
127
>>> smallest_good_prime('?89')
389
>>> smallest_good_prime('?89?')
2897
>>> smallest_good_prime('?2?4?')
12347
>>> smallest_good_prime('1??4?7')
123457

学霸联盟
essay、essay代写