0

This is my code:

N=int(stdin.readline())
Arr=[]
for j in range(N):
    Arr.append(int(stdin))
print(Arr)

I got the following error: TypeError: int() argument must be a string, a bytes-like object or a real number, not '_io.TextIOWrapper'

1
  • When you read a line you will get a string. You think have to Commented Feb 4, 2022 at 12:48

2 Answers 2

2

To read one line from the console, use the input() function. After that use the split(" ") to split str to the string array by space delimiter.

line = input()
str_arr = line.split(" ")

To convert str array to int array. use the bellow code.

int_arr = [ int(item) for item in str_arr]
Sign up to request clarification or add additional context in comments.

Comments

0

There is a direct way to input list elements in python in a single line:

lst = [x for x in input().split()]          // for string input

and just use a int(x) inplace of x to convert into integers and store in list

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.