def location( (xs, key) : Wc will implement our own function-version of the index() method
(which you may not call). Search through the list xs, and when you find a value equivalent to key,
return that non-negative index. When it's not found, return the None value. The leftmost match is
reported when multiple matches of the key are present
assume that xs is a list.
Restriction can't call .index() method - just loop through manually and seck the key
location( [3,4,5,6,4,4,4,4,4], 4)
location( [100, 105, 110], 234)
def fibonacci(n): The fibonacci sequence begins with two 1's, and cach successive spot is the
sum of the previous two. If we were to store those values in a list. it would begin ast
fibs = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ***
Given an index into that list, n, report the nth fibonacci number.
Note though there is a well-known recursive solution, it is well-known because it is
pathologically slow! Wc have one larger test-case that will somewhat require that you use
loop-based solution. Restriction no recursion.
def int_sqrt(n): Find the largest integer whose square isn't bigger than the parameter n.
assume that n is a positive integer.
Restriction: you may not import or use math. sqrt
# 3*3 happens to perfectly equal 9.
# 5*5 is the largest Square not larger than 25
# n:25 35 all answer with 5.
# 6*6 happens to perfectly equal 36.
def sum_evens_2d(xss): Given a "two-dimensional list" of integers - that is, a list where each
value in it is a list of integers - find all the even numbers and sum them together. You will need
more than a single loop for this!
assume that xss is a list where cach value is a list of integers.
Restriction: you may not call sum(). (It would have included the odds anyways).
2+4+6 == 12
2+4+6+8 == 20
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction
of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.
def location(xs, key):
for i in range(len(xs)):
if xs[i]== key: