1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sergejj [24]
3 years ago
7

Write a function index(elem, seq) that takes as inputs an element elem and a sequence seq and returns the index of the first occ

urrence of elem in seq. The sequence seq can be either a list or a string. If seq is a string, elem will be a single-character string; if seq is a list, elem can be any value. If elem is not an element of seq, the function should return the length of the sequence. Dont forget that the index of the first element in a sequence is 0. Here are some examples: >>> index(5, [4, 10, 5, 3, 7, 5]) solution
Computers and Technology
1 answer:
Delicious77 [7]3 years ago
5 0

Answer:

def index(elem, seq):

   for i in range(len(seq)):

       if elem == seq[i]:

           return i

   

   return len(seq)

print(index(5, [4, 10, 8, 5, 3, 5]))

Explanation:

Create a function named index that takes elem and seq as parameters

Create a for loop that iterates through the seq. If elem is equal to the item in the seq, return the i, index of the item.

If the elem is not found in the seq, this means nothing will be returned in the loop, just return the length of the seq, len(seq)

Call the function with given parameters and print the result

Note: Since 5 is in the list in the example, the index of the 5 which is 3 will be returned

You might be interested in
Which software fits into the category of a productivity software?
aniked [119]
I believe photoshop since it has elements of productivity
4 0
3 years ago
How do you answer a question on here
Monica [59]
Didn’t you just make a question right now?
4 0
3 years ago
Read 2 more answers
Sarah is starting her job at the local ice cream shop. What can Sarah do to make a good impression on her first day of work?
Whitepunk [10]
A is the correct answer.
8 0
3 years ago
Read 2 more answers
If you do not want the border style to carry forward each time the enter key is pressed, you need to ____.
ANEK [815]
Hello <span>Endermss2118 </span>

Answer: If you do not want the border style to carry forward each time the enter key is pressed, you need to Clear formatting


Hope This Helps
-Chris
8 0
3 years ago
Describe orderly how to save a Word document into a folder​
ivann1987 [24]
In order to do that you go onto the document you are going to save, on the top left it has the word “file”, click on that, once clicked it should say “Save as” and click on that, it will then ask you where you want it or which folder and you click the folder you want and finally click “save”
7 0
3 years ago
Other questions:
  • To include totals and other statistics at the bottom of a datasheet, click the ____ button on the HOME tab to include the Total
    12·1 answer
  • Difference between windows 2000 professional and service pack
    11·1 answer
  • How many of yall are willing too sub to my channel called "Space Juice" with around 200 subs?!​
    11·1 answer
  • Hardware refers to programs and protocols used on a computer system.<br><br> True<br> False
    8·2 answers
  • What is dialog box? ​
    7·1 answer
  • 3. Maria is in charge of consolidating the names of the participants of the two-day virtual
    13·1 answer
  • Rebbeca has finished with the research and outline portion of her slide presentation. Now, the next logical step is to begin wor
    11·1 answer
  • Who Invented Abacus!
    15·1 answer
  • How is an operating system like a translator?
    12·1 answer
  • 8. Give regular expressions with alphabet {a, b} for
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!