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

ex. 0.3.1 #11

Open
Casper17-max opened this issue Jul 19, 2021 · 3 comments
Open

ex. 0.3.1 #11

Casper17-max opened this issue Jul 19, 2021 · 3 comments

Comments

@Casper17-max
Copy link

I think I have the minimum and index of x:
image

but I don't know how to put them together in the minimum function:
image

@joachimkrasmussen
Copy link
Contributor

Hi Casper

Take a look at the cell that you ran as [80]. In each round of the loop, you printed an index and the element in a list that was associated with that index.

Now, you want to write a function that does a similar thing. I.e. it should end with

    return (some_index, some_element)

However, instead of just printing/returning all indices and elements, you want to return only the index that is associated with the minimum value and that exect minimum_value. You cannot print enumerate(x) as this is a very different type of object.

Was this helpful? Otherwise, I can provide an example.

Best,
Joachim

@Casper17-max
Copy link
Author

Hi,
An example would be great.
I really don't understand the general notation or intuition for how to write it.
The following code produces neither output nor error message, so I don't understand what's wrong.
image

@joachimkrasmussen
Copy link
Contributor

Hi Casper,

One problem in the function above is that you are calling the function minimum() within minimum() itself.

Consider the function below that takes a list of numbers as inputs and finds the index and value associated with the first prime number in the list. Try and explain each step for yourself and see if this helps you write the right minimum function.

Best,
Joachim

def find_first_prime(my_list):
    
    my_index, my_val = float('inf'), float('inf')
    
    for (number_index, value) in enumerate(list_of_numbers):
        
        if my_val == float('inf'):
            
            cont = 0
            for i in range (2,value):
                if value % i == 0:
                    cont = 1
                    
            if cont == 0:
                my_index = number_index
                my_val = value
                
    return (my_index, my_val)

list_of_numbers = [4, 9, 6, 16, 13, 3, 10, 12]

print(find_first_prime(list_of_numbers))

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

No branches or pull requests

2 participants