Python "ValueError: incomplete format" after printing ("stuff%"% "thingy")

My goal with this code is that when you insert a specific number, you will print the number and some other result based on what you typed. For some reason, what I have here is giving a "ValueError: incomplete format" error. This has something to do with%. What does the error mean, and how to fix it? Thanks!

variable = "Blah"
variable2 = "Blahblah"

text = raw_input("Type some stuff: ")

if "1" in text:
    print ("One %" % variable)
elif "2" in text:
    print ("Two %" % variable2)
+4
source share
3 answers

he expects another character to follow %in the line to tell him how to represent variablethe line.

"One %s" % variable "One {}".format(variable), .

+10
>>> variable = "Blah"
>>> '%s %%' % variable
    'Blah %'
>>> 
+2

simple way:

print ("One " + variable)
+1
source

Source: https://habr.com/ru/post/1623348/


All Articles