Python Forum

Full Version: Newbie here. What's wrong with my code?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey Guys, I'm new to Python and Coding stuff. I just started using Python for my course. So I decided to See a few Tutorials but for this particular code I can't seem to make it work. Please Help Me.

This is the code:

print (("%s is a very #s person. He usually spend all his time #s.") % (input("Please enter a name: ")), (input("Please enter adjective: ")), (input("Please enter 'ing' verb: ")))
This is my result:

Output:
Please enter a name: Bill Please enter adjective: Deranged Please enter 'ing' verb: Killing Bill is a very #s person. He usually spend all his time #s. Deranged Killing
As you can see, the #s is still visible and it did not substitute with both Adjective and Ing.

Note: I have edited some of the code since the OP who make that tutorial using Python 2. This is the closest result I can get.

Original Code:

print (("%s is a very %s person. They usually spend all their rime %s.") % input ("Please enter a name: "), input ("Please enter an adjective: "), input ("Please enter an 'ing' verb: "))
The code that you call "Original' is actually python3 code, not python2 code.
Old-style string formatting, that you use here is using % as a placeholder, not #. # is simply char as any other, without special meaning and is printed as is.
it is recommended that you use new-style formatting.
print('{} is my name'.format('GalaxyCR'))
Thanks buran for the help and the edit. I'll try to improve and fix it.
btw, I found the tutorial on youtube and the guy there is using python2 indeed (e.g. using raw_input, not input). So the 'original code' is in fact not that 'original' one...
also, in python3.6. there is also so called formatted string literals or simply f-strings:
name = "GalaxyCR"
print( f"He said his name is {name}.")
PEP498 for detailed discussion