-1

I'm new to coding and can't seem to figure out the issue with my code. So, I've created a variable. Now I am trying to use that variable in a string input, but I keep getting a

TypeError: input expected at most 1 arguments, got 3.

Any help would be appreciated!

E.g.

import random
number = random.randint(1,100)
random = str(input('Is', number, 'a prime number? '))
0

4 Answers 4

1

The input method waits for one string, one that you need to build, here are ways (also it already returns a string, remove the str)

# f-string
random = input(f'Is {number} a prime number? ')

random = input('Is %s a prime number?' % number )
Sign up to request clarification or add additional context in comments.

Comments

1

Replace random = str(input('Is', number, 'a prime number? ')) with random = str(input(f'Is {number}, a prime number? ')) since input takes 1 string. (Requires Python 3.6 and above)

Comments

0

The input function takes only one argument, as the error message indicates, the string to display as a prompt, unlike the print function that can take multiple arguments. What you need to do is to combine all arguments in a single string. There are multiple ways to do it:

# string concatenation
random = input('Is ' + str(number) + ' a prime number? ')

# string formatting
random = input('Is %d a prime number?' % number)

# f-strings
random = input(f'Is {number} a prime number?')

Comments

0
import random
number = random.randint(1, 100)

random = str(input('Is ' + str(number) + ' a prime number? '))

1 Comment

Okey, I will put a text :)