Please help with %s problem - HELP


#1

https://gyazo.com/e6f527b2c3e5a6e265f86232e349f3a8

As u can see my % doesnt take the %s place, why so?

print("Welcome to the hardest quiz ever!\n")
correct = 0
incorrect = 0
total = 0
number = 0
question = "1 + 1"
x = 1
answer = 2

def questions(x, question, answer):
    a = input("%s Question:\n%s") % (x, question)
    attempts = 3
    for i in range(1, 4):
        if a == answer:
            print("That is correct!")
            correct = correct + 1
            print(correct)
            return correct 
            break
        else:
            print("That is incorrect. You have %s tries left.") % (attempts)

questions(x, question, answer)

ps. just help me with the %s problem, my script isnt done yet. So there might be some other mistakes


#2

well the string is part of input, so the things you want on the placeholder should be as well:

a = input("%s Question:\n%s" % (x, question))

and x doesn't seem to be a string, so %s doesn't seem like a suitable placeholder


#3

So it have to be a string if I want to replace the %s with the %. It cant be an int


#4

the s of %s is for string, you could use %i or %d instead as you can read here


#5

w8 is it then possible to have two diffrent %s in one like:
a = input("%i Question:\n%s") % (x, question)

where x is an int, while question is a string.
I just still get the error. How would u make it if its not possible this way?


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.