0

Ok so basically I have the following code:

name=raw_input("What is your name?")
quest=raw_input("What is your quest?")

print ("As so your name is %s, your quest is %s ") %(name,quest)

This runs perfection in Python 2.7.9

I have tried to run this same exact code in Python 3.4.2 and it does't work (figured), so I modified it to this thinking it would work:

name=input("What is your name?")
quest=input("What is your quest?")

print ("As so your name is %s, your quest is %s ") %(name,quest)

And this:

name=input("What is your name?")
quest=input("What is your quest?")

print ("As so your name is {}, your quest is {} ") .format(name,quest)

And of course that didn't work either, I have searched for over an hour now multiple sites, what am I missing here? How do you do this in Python 3.4.2, all I keep getting is sites and answers showing you the first way (I listed), and all it does is work on the older version python 2.

Thanks

  • This seems to be fairly similar to this question. – jpanda109 Dec 07 '15 at 20:19
  • Yeah thats one of the answers I read and found, however it did not answer my question (he wasn't using print). The "print function" was what was messing me up, thanks to the guy below that answered, it works now. – Jaymes Deen Dec 07 '15 at 20:30

2 Answers2

0

print is a function in Python 3. Thus, doing print(...).format(...) is effectively trying to format the return value of the print() call, which is None.

Call .format() on the string you want formatted instead:

print("As so your name is {}, your quest is {} ".format(name,quest))
senshin
  • 10,022
  • 7
  • 46
  • 59
0

Your modified code was nearly right, you just needed to move a bracket to apply the % operator to the string instead of the print function result.

So change this:

print ("As so your name is %s, your quest is %s ") % (name, quest)

to this:

print ("As so your name is %s, your quest is %s " % (name, quest))

and it runs fine in Python 3.

foz
  • 3,121
  • 1
  • 27
  • 21