Search code examples
pythonvariablesinputargumentsraw-input

Inserting variables into an input() command in python


Hello I am new to the world of programming and I need a bit of help. I was trying to finish some work that I had to do for my Python class and I came across a problem that I couldn't fix and couldn't find answers on the web for. Here is my problem. When I code something like:

a = "apples"
t = "tomatoes"
answer = raw_input("Do you prefer eating ", p," or ", t, " ?")
print answer

It gives me an error message on line 3 saying: "TypeError: Win32Input() takes at most 2 arguments (6 given)" What did I do wrong and how can I fix it? Thanks in advance. :)


Solution

  • raw_input's input is not the same as print's, it takes a string, so you have to create a string by formatting it:

    answer = raw_input("Do you prefer eating {} or {}?".format(p, t))