Doubt with Python neighbor numbers

Asked

Viewed 242 times

-1

I wonder if someone could help me in this code in order to calculate neighboring numbers (numbers in common) in two arrays, but does not return output.

i = 0
j = 0
k = 0
input1 = input()
input2 = input()
input1.split(", ")
input2.split(", ")
while i < len(input1):
    while j < len(input2):
        if input1[i] == input2[j]:
            result = input1[i]
            print(result)
        j = j + 1
    i = i + 1
  • 2

    What would be "neighboring numbers"? And what will be the program entries? What should be the output?

  • Just remember that when working with numbers that came from an input, you should convert them to float or int, for example float(input1), because you’re getting a string, also check that if

  • Carlos, the common numbers of two arrays.

1 answer

0


The error is very simple, just use the raw_input() at the end of input(). Basically the input() it will receive and interpret as a list of integers, and when you try to use the input1.split(", ") it will not recognize the command, but when you use the raw_input() you create a string list, and in that list you use the input1.split(", ") and can transform again to int if necessary.

  • But the error was not in the split, because I tested the array. And I am programming in Python 3. But thanks for the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.