Play it, Sam syntax question


#1

https://www.codecademy.com/en/courses/python-beginner-en-4XuFm/2/1?curriculum_id=4f89dab3d788890003000096

On the Play It, Sam exercise, I feel like maybe I am missing something. Is there a reason why it would ONLY accept print "Turn", turn + 1? I had it as print "Turn %s" % (turn + 1), and while it functioned flawlessly, they wouldn't accept that as an answer. Is it just because of the limitations of the platform? Or is there a legitimate reason why mine was wrong? Just wondering, because I spent a long time trying to figure out what went wrong in the code.


#2

Hi @josiahpinner,

Technically, nothing is wrong with doing this ...

    print "Turn %s" % (turn + 1)

... in fact, many would consider it to be better programming style than this ...

    print "Turn", turn + 1

Codecademy applies a submission correctness test (SCT) to your code after you submit it. In this exercise, it looks for the turn numbers as individual units of output. This ...

    print "Turn", turn + 1

... produces the output in two units, with the second one being what Codecademy is looking for as the turn number.

Although this produces output that looks the same ...

   print "Turn %s" % (turn + 1)

... the SCT considers the output from that line to be a single unit, and does not recognize it as the turn number.

Try this to verify that it is really the turn number, rather than what precedes it on the same line, that the SCT is seeking, and note that it will be accepted ...

    print "Turn ...", turn + 1

#3

Thank you for the clarification @appylpye! I just wanted to make sure that I understood it correctly. The last thing I want to do is pick up bad habits when I'm just starting out.


#4

Actually, your version of that line was an improvement. After completing the current exercise, you can customize that line as you want, and it will not be a problem.

Here's another way you could do it, provided that you wait at least until the next exercise ...

    print "Turn {:d}".format(turn + 1)

#5

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