Correct) Questions with Accurate
Answers
# unit test case
import unittest
def multiply_numbers(x, y):
#add your code here
return x * y
# add your code here
class TestForNone(unittest.TestCase):
def test_when_a_is_null(self):
try:
self.assertIsNone(multiply_numbers(5, None))
except AssertionError as msg:
print(msg)
if __name__ == '__main__':
unittest.main() correct answer if x is None:
print("x is a null value")
return y
,elif y is None:
print("y is a null value")
return x
else:
return x * y
# verify we only have digits
def check_numeric_value(wg_int):
return isinstance(wg_int, int)
#return true if numeric value is an integer, else return false.
#Hint: use isinstance function
# verify if the string is null
def check_null_string (wg_string):
# check if wg_string is not null return true else return false
if __name__ == '__main__':
wg_string = "I like dogs." # use keyword None to test
wg_int = 12345
, print(check_null_string (wg_string))
print(check_numeric_value(wg_int)) correct answer return
isinstance(wg_int, int)
return wg_string is not None
#check if the input range is between 1 and 10 for the range validation
check
if __name__ == '__main__':
r = range(1,10)
num = int(input())
# create conditional statement for range check here correct answer r =
range(1,11)
num = int(input())
if num in r:
print("The number input is in the range from 1 and 10.")
else:
print("The number input is not in the range from 1 and 10.")