in Education by
Working on this problem for a python course and can't for the life of me figure out why this doesn't work. It is better if I get an error than printing 0! The problem gives me the variable x with the string shown and needs to print the index of the first time y is used. x = 'Poisson geometry plays an important role in noncommutative geometry.' y = 'u' i = 0 while i == 0: for o in x: if o == y: print(y, "is first seen in index = ", y.index(o)) i += 1 Code is shown returns: u is first seen in index = 0 Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Since you want index in x?. You need to use x.index(o) where searches for o in x. x = 'Poisson geometry plays an important role in noncommutative geometry.' y = 'u' i = 0 while i == 0: for o in x: if o == y: print(y, "is first seen in index = ", x.index(o)) i += 1 The correct way to write it is without a loop: x = 'Poisson geometry plays an important role in noncommutative geometry.' y = 'u' print(y, "is first seen in index = ", x.index(y)) output: u is first seen in index = 51 If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

Related questions

0 votes
    I am getting errors for the code when running it on a 'tips' dataset but I can run it on a tulips dataset ... . Am I missing something? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have two data frames with the closest matching DateTime index, sometimes matching. An object is to merge two of ... I achieve this? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    To the data frame df: Player Team Points Mean Price Value Gameweek 1 Jim Leeds 4.4 4.40 10.44 0.44 2 Jim ... scalar What am I missing? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    Here is my sample string: [true, {"name": "NameofItem", "amount": "1", "price": 100, "sellerName": " ... seem to make that work. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have 2 data frames df1 Name 2010 2011 0 Jack 25 35 1 Jill 15 20 df2 Name 2010 2011 0 Berry 45 25 1 ... used the code df1.add(df2) Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    It is a principal question, regarding the theory of neural networks: Why do we have to normalize the input for ... is not normalized? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why Python is better than R for Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why Python is used in Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    When I run pip3 install -r requirements.txt on the project I get this error message: pip._vendor.pkg_resources. ... on my machine. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Here's the code: ''' file_path = (r'C:\Users\Luka\Desktop\Pyhton exercises\pi_digits.txt') with open( ... file_object: print(line) Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    from datetime import date import dataclasses @dataclasses.dataclass(frozen=True) class A: date: date = dataclasses.field ... by design? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    In the python documentation, an instance of a named_tuple is created by using the below code: Point = named_tuple(' ... of doing it? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm hoping to use either Haskell or OCaml on a new project because R is too slow. I need to be able to ... in either Haskell or OCaml? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...