Single Digit
Write the function single_digit(integer)
, that returns True
if the parameter integer
is a non-negative, single digit integer and False otherwise.
Example
Test Code | Output |
---|---|
print(single_digit(0)) | True |
print(single_digit(9)) | True |
print(single_digit(10)) | False |
print(single_digit(-1)) | False |
Test Code | Output |
---|---|
print(rps_string(0)) | rock |
print(rps_string(1)) | paper |
print(rps_string(2)) | scissors |
print(rps_string(3)) | error |
print(rps_string(-1)) | error |
Test Code | Output |
---|---|
print(is_leap(1900)) | False |
print(is_leap(2000)) | True |
print(is_leap(1996)) | True |
print(is_leap(2015)) | False |
print(is_leap(2016)) | True |
Hint
You can use the mode,
%
, operator to test divisibility. Ifyear % 4
is 0, then year is divisible by 4.Dont forget that you can use logical constructs to reduce the complexity of the condition checks.
Submission
Please show your source code and run your programs for the instructor or lab assistant. Only programs that have perfect functionality will be accepted as complete.