python - Trying to access the n-th element of a list gives ValueError when using .index() -


I want to print 2 lists using the format function:

  Planets | Distance from Sun Mercury. 0.4 AU Venus | 0.7 AU Earth | 1.0 AU Tues | | 1.5 AU Jupiter | 5.2 au shani | | 9.5 AU Uranus | 19.6 a. Neptune | 30.0 AU  

Here is the code:

  Planets = ["Planet", "Mercury", "Venus", "Earth", "Mars" "Jupiter", "Saturn", "Uranus", "Neptune"] Distance = ["Fierce to the Sun", "0.4", "0.7", "1.0", "1.5", "5.2", "9.5", " ("{} | {}". Format (Planets Indexes (i), Distance .index (i)))   / Pre> 

.index () appears in the list for a value and returns the index of that value in the list if it can not get that value in the list , Then this indicates a valueError That does not get value - eg: you do not have 0 in your list I think you are confusing it with the planets [i] which The index will get index from the list.

However, there is a very easy way to "combine" "two lists, and print out results from them - you do not need to put an index on them, To be repeated on, for example:

  for P, d in zip (planet, distance): In this case, you can avoid the  .format  because it 

P> given:

  data = [1, 7, 5]  

data in <3> item value What is it?

  print (data [2]) # 5  

What is the index status of the first 7 in the list?

  print (data.index (7)) # 1  

What is the value of the list in the second position?

  print (data [1]) # 7  

What is the first condition 100 in the list?

  Print (data.inx (100)) # traceback (most recent call end): # file "& lt; pyshell # 8" gt; Line 1, & lt; Module & gt; # Data.index (100) # Value error: 100 is not in the list  

Comments