-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Brute-force argorithms", exercise 4 #21
Labels
exercise
Exercise
Comments
|
|
# test case
def test_my_range(stop_number, expected):
result = my_range(stop_number)
if expected == result:
return True
else:
return False
# algorithm
def my_range(stop_number):
output_list = []
index = 0
while index < stop_number:
output_list.append(index)
index += 1
return output_list
# run test
print(test_my_range((5), [0, 1, 2, 3, 4]))
print(test_my_range((0), []))
print(test_my_range((2), [0, 1]))
# returns
# True
# True
# True
# run algorithm
print(my_range(5))
# returns [0, 1, 2, 3, 4] |
Hi all, please remember that each testing function must input the parameter of the function to test and the expected result. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write in Python the function
def my_range(stop_number)
, which behaves like the built-in functionrange()
introduced in Section "Insertion sort" and returns a proper list, and accompany the function with the related test case. It is not possible to use the built-in functionrange()
in the implementation.The text was updated successfully, but these errors were encountered: