pythonfunctionvariablessyntax

How to insert a variable into an "input" function


I want show two variables in a prompt line in Python as this:

a = 35
b = 11
captcha = int(input(a, '+', b '='))

It must looks like: 35 + 11 =

The terminal say there is a SyntaxError. Can someone fix my syntax please? Thanks!


Solution

  • You've got two problems.

    You miss the third comma to separate b and =. Then input takes only one argument. If you try and concatenate strings in a function, python will think you are trying to add multiple arguments. Try using f-strings instead.

    captcha = int(input(f'{a} + {b} ='))