I’m trying to write a script that will prompt a user for an answer to an addition problem. To do this I need to pass a variable to the string that is displayed during the prompt but I’m having a hard time figuring out how to do this.
I’ve come up with the following code that does not work:
operand = 4
ans = input('What is 4 + {0} ?') .format(operand)
returns:
'What is 4 + {0} ?'
But I want it to be:
'What is 4 + 4 ?'
How can I do this?
You need to modify the string argument to input. In your code you are trying to format the input string returned by the
inputfunction