Skip to content
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

Open
essepuntato opened this issue Nov 17, 2024 · 10 comments
Open

Lecture "Brute-force argorithms", exercise 4 #21

essepuntato opened this issue Nov 17, 2024 · 10 comments
Labels
exercise Exercise

Comments

@essepuntato
Copy link
Contributor

Write in Python the function def my_range(stop_number), which behaves like the built-in function range() 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 function range() in the implementation.

@essepuntato essepuntato added the exercise Exercise label Nov 17, 2024
@ValkyrieCain9
Copy link

#DEFINING MY RANGE FUNCTION

def test_my_range(stop_number):
    if my_range(stop_number) == list(range(stop_number)):
        return True
    else:
        return False

def my_range(stop_number):
    output_list=[]
    i = 0
    while i < stop_number:
        output_list.append(i)
        i+=1
    return output_list

print(test_my_range(4))
#returns True

@maridematteis
Copy link

Screenshot 2024-11-19 alle 16 47 20

@lisitein
Copy link

def test_my_range(stop_number):
    result = my_range(stop_number)
    if list(range(stop_number)) == result:
        return True
    else:
        return False

def my_range(stop_number):
    output_list = []
    i = 0
    while i < stop_number:
        output_list.append(i)
        i = i+1
    return output_list

print(range(2))
# range(0, 2)
print(test_my_range(2))
# True
print(my_range(2))
# [0,1]
        

@shiho1000
Copy link

shiho1000 commented Nov 19, 2024

# 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]

@essepuntato
Copy link
Contributor Author

Hi all, please remember that each testing function must input the parameter of the function to test and the expected result.

@arinee01
Copy link

Снимок экрана 2024-11-20 в 15 42 44

@theair-hub
Copy link

image

@ERendall
Copy link

image

Further ooof.

@nicoldamelio
Copy link

Screenshot 2024-12-05 alle 21 44 46

@martinaucch
Copy link

def test_my_range(stop_number, expected):
    result = my_range(stop_number)
    if expected == result:
        return True
    else:
        return False

def my_range(stop_number):
    output_list = list()
    if stop_number > 0: 
        while len(output_list) < stop_number: 
            output_list.append(stop_number)
            enumerate_list = [position for position, item in enumerate(output_list)]
        return enumerate_list
    else:
        return output_list
    
print(test_my_range(4, [0,1,2,3]))
print(test_my_range(0, []))
print(test_my_range(1, [0]))

Screenshot 2024-12-08 alle 19 09 08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exercise Exercise
Projects
None yet
Development

No branches or pull requests

10 participants