python - Input multiple lines in pycharm -


this question has answer here:

i error when try input program tries find location of number in array, want give entire input @ 1 go how can it, there easier way? thank you. following error when trying execute in console in pycharm

example

input

2
4
1 2 3 4
3
5
10 90 20 30 40
40

 # returns index of x in arr if present,  # else returns -1  def search(arr, x):      n = len(arr)      j in range(0,n):          if (x == arr[j]):              return j      return -1   # input number of test cases  t = int(raw_input())   # 1 one run input test cases  in range(0,t):       # input size of array      n = int(raw_input())       # input array      arr = map(int, raw_input().split())       # input element searched      x = int(raw_input())       print(search(arr, x)) 

on pycharm console input:

2   4 1 2 3 4   3   5   10 90 20 30 40   40   

output

 traceback (most recent call last):    file "<input>", line 8, in <module>    valueerror: invalid literal int() base 10: '2\n 41 2 3 4\n 3\n 5\n 10 90 >20 30 40\n 40' 

bcoz input string can not convert int ('2\n 41 2 3 4\n 3\n 5\n 10 90 >20 30 40\n 40') should parse input value '\n' , ' ' fist , convert int numbers


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -