0

I'm getting type error for following line:

a, b = task_one(int(input("Enter number of your choosing: "), input("Enter second number: " )))
TypeError: 'str' object cannot be interpreted as an integer

I don't understand why input is classified as a string when I enter integers and use int() function.

1
  • You're passing two strings as arguments to int(). It's complaining about the second one, which is the optional base argument and must be an integer. You can't convert multiple strings within one call to int(). Commented Jan 23, 2021 at 14:56

3 Answers 3

2

I think this is the better way when you are taking multiple inputs in single line.

a,b = list(map(int, input().split()))
Sign up to request clarification or add additional context in comments.

4 Comments

I tried using split() in a slightly different way before but it didn't work. I tried your suggestion anyway but I got the same error as back then. It says I'm missing one required positional argument 'b'
You have to give both input in same line using space, for example "2 3" these will be your 2 inputs
I know but for some reason it doesn't work
You can visit this for references.
1

My guess is that you would like each of the inputs to be integers, therefore you need to convert each of them on their own -

a, b = task_one(int(input("Enter number of your choosing: ")), int(input("Enter second number: " )))

Comments

1

This code:

input("Enter number of your choosing: "), input("Enter second number: " )

For example, input 1 and 2, returns ('1', '2'). It cannot be converted to int:

>>> input("Enter number of your choosing: "), input("Enter second number: " )
Enter number of your choosing: 1
Enter second number: 2
('1', '2')

If task_one is a function that takes two ints, you should write it this way:

a, b = task_one(int(input("Enter number of your choosing: ")), int(input("Enter second number: " ))))

1 Comment

It isn't a tuple, it's just two arguments to int().

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.