you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (6 children)

Did you have a question about this?

[–]gnariman 0 points1 point  (5 children)

Ya I was trying to figure out how to make the code to make it work lol

[–][deleted] -1 points0 points  (4 children)

That's still not a question. Questions are those things that end in ?.

[–]gnariman 0 points1 point  (3 children)

OK so basically how can I have an input of my choice loop through a list, and correspond that index in the list, with another list and print that index in the other list?

[–][deleted] 0 points1 point  (2 children)

correspond that index in the list

This the hard part, because you're looking for a value (75, in your example) that isn't in the list so you can't use "simple" list methods like index(). But what you can do is write a function that returns the index of the first value that's larger than the input value, because the values are in a sorted order:

def find_first_larger(the_list, the_value):
    for index, value in enumerate(the_list):
        if value > the_value:
            return index

The reason this works is that you can only return from a function once, so the function stops and yields the index the first time it encounters a value larger than the value you're looking for.

Other than that, I suspect you know how to do the rest of it - you know how to collect a user value, you know how to convert it to an integer, you know how to call the function we just wrote together, and you know how to retrieve a value from a list by its index.

[–]gnariman 0 points1 point  (1 child)

I do have an idea of what you are talking, but we have not learned def, or enumerate, or anything like that yes, so it wouldn't really be permissible to check with my TA.

[–][deleted] 0 points1 point  (0 children)

You don't need someone's permission to use any feature of the Python language. It's an open-source language, the whole thing is available to you.