<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: kvcoders</title>
    <description>The latest articles on DEV Community by kvcoders (@kvcode_327f87ccbbb63).</description>
    <link>https://dev.to/kvcode_327f87ccbbb63</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4141650%2Fb17829b3-e7c8-4b81-a107-ae268497eeb7.jpg</url>
      <title>DEV Community: kvcoders</title>
      <link>https://dev.to/kvcode_327f87ccbbb63</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kvcode_327f87ccbbb63"/>
    <language>en</language>
    <item>
      <title>KVCODERS: The subtle bug in comparing Python output as text</title>
      <dc:creator>kvcoders</dc:creator>
      <pubDate>Thu, 24 Sep 2026 17:08:35 +0000</pubDate>
      <link>https://dev.to/kvcode_327f87ccbbb63/kvcoders-the-subtle-bug-in-comparing-python-output-as-text-1olp</link>
      <guid>https://dev.to/kvcode_327f87ccbbb63/kvcoders-the-subtle-bug-in-comparing-python-output-as-text-1olp</guid>
      <description>&lt;p&gt;KVCoders has an "Output Practice" mode where students see a Python (or SQL) snippet and have to predict its exact printed output — a real, common CBSE Class 11–12 Computer Science exam question type. Grading it sounds trivial: run the reference code once, store the expected output, compare it to what the student typed. It isn't.&lt;/p&gt;

&lt;p&gt;The first version did exactly that — a plain string comparison — and it produced false negatives constantly. A student who correctly predicted &lt;code&gt;[1, 2, 3]&lt;/code&gt; but typed &lt;code&gt;[1,2,3]&lt;/code&gt; (no space after the commas) was marked wrong, even though Python's own &lt;code&gt;print()&lt;/code&gt; would show the spaced version and the student clearly understood the actual value. The same problem showed up around dictionary colons (&lt;code&gt;{'a':1}&lt;/code&gt; vs &lt;code&gt;{'a': 1}&lt;/code&gt;) and generally anywhere CBSE's own textbook examples are inconsistent about spacing that Python itself normalizes on output.&lt;/p&gt;

&lt;p&gt;The fix isn't "trim whitespace" — that's too blunt, because whitespace is sometimes the actual answer. A question testing string formatting might have &lt;code&gt;"R*A*D*A*R*"&lt;/code&gt; as a genuinely correct output where every character matters, and a multi-line &lt;code&gt;print&lt;/code&gt; output's internal line breaks are meaningful, not incidental. So the real requirement was narrower: normalize spacing specifically around Python's own container punctuation (&lt;code&gt;,&lt;/code&gt; and &lt;code&gt;:&lt;/code&gt; inside &lt;code&gt;[...]&lt;/code&gt;, &lt;code&gt;(...)&lt;/code&gt;, &lt;code&gt;{...}&lt;/code&gt;), and leave everything else — including anything inside a quoted string literal, at any nesting depth — completely untouched.&lt;/p&gt;

&lt;p&gt;KVCoders' actual normalizer (&lt;code&gt;normalize_output_answer()&lt;/code&gt; in &lt;code&gt;examiner/includes/output_scoring.php&lt;/code&gt;) is a small character-by-character parser that tracks two pieces of state as it walks the string: bracket depth (how many &lt;code&gt;[&lt;/code&gt;/&lt;code&gt;(&lt;/code&gt;/&lt;code&gt;{&lt;/code&gt; are currently open) and whether it's currently inside a quoted string (and if so, which quote character, so it can handle an escaped quote correctly and not exit early). Outside of quotes, at any depth greater than zero, a comma or colon gets its trailing whitespace collapsed to exactly one space (matching how Python itself prints a list or dict) — but only if what follows isn't a closing bracket, so &lt;code&gt;[1, 2]&lt;/code&gt; normalizes consistently without producing a stray trailing space before the &lt;code&gt;]&lt;/code&gt;. Inside quotes, every character — including whitespace — passes through byte-for-byte, so string &lt;em&gt;content&lt;/em&gt; can never be silently rewritten by a grading rule.&lt;/p&gt;

&lt;p&gt;This function is called from three separate places — the web submit endpoint, the Android app's API submit endpoint, and (identically) the client-side preview — specifically so none of them can quietly drift into disagreeing about what counts as a correct answer, which used to be a real, separate bug class before it was consolidated into one shared implementation.&lt;/p&gt;

&lt;p&gt;The broader lesson wasn't really about string parsing. It's that "auto-graded" for a board-exam audience has to tolerate exactly the kind of formatting variance a human teacher would silently forgive — without becoming so lenient that it stops catching genuinely wrong answers. Getting that boundary right mattered more than the parsing logic itself.&lt;/p&gt;

&lt;p&gt;This runs in production at &lt;a href="https://kvcoders.in/output_test/select_chapter.php?utm_source=devto&amp;amp;utm_medium=publishing&amp;amp;utm_campaign=batch01" rel="noopener noreferrer"&gt;kvcoders.in&lt;/a&gt; for CBSE Class 11–12 CS/IP output-prediction practice. Happy to answer questions in the comments.&lt;/p&gt;

</description>
      <category>codequality</category>
      <category>computerscience</category>
      <category>python</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
