python - Evaluation of 'not (False and True)' -
i came across example ("hacking secret ciphers python", p135) , i'm confused:
not (false , true) the example states evaluates false, fail see why. if parentheses modify precedence surely evaluating:
not (false) which evaluates true, doesn't it? or missing something?
// output functions configurable. 1 appends text // pre element. function outf(text) { var mypre = document.getelementbyid("output"); mypre.innerhtml = mypre.innerhtml + text; } function builtinread(x) { if (sk.builtinfiles === undefined || sk.builtinfiles["files"][x] === undefined) throw "file not found: '" + x + "'"; return sk.builtinfiles["files"][x]; } // here's need run python program in skulpt // grab code textarea // reference pre element output // configure output function // call sk.importmainwithbody() function runit() { var prog = document.getelementbyid("yourcode").value; var mypre = document.getelementbyid("output"); mypre.innerhtml = ''; sk.pre = "output"; sk.configure({ output: outf, read: builtinread }); (sk.turtlegraphics || (sk.turtlegraphics = {})).target = 'mycanvas'; var mypromise = sk.misceval.asynctopromise(function() { return sk.importmainwithbody("<stdin>", false, prog, true); }); mypromise.then(function(mod) { console.log('success'); }, function(err) { console.log(err.tostring()); }); } <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript"></script> <script src="http://www.skulpt.org/static/skulpt.min.js" type="text/javascript"></script> <script src="http://www.skulpt.org/static/skulpt-stdlib.js" type="text/javascript"></script> <h3>try this</h3> <form> <textarea id="yourcode" cols="40" rows="10">print(not (false , true)) </textarea> <br /> <button type="button" onclick="runit()">run</button> </form> <pre id="output"></pre> <!-- if want turtle graphics include canvas --> <div id="mycanvas"></div>
this covered in the errata:
page 135, interactive shell should this:
>>> not false , false # not false evaluates first true >>> not (false , false) # (false , false) evaluates first false(thanks omer chohan)
it has been corrected in the online version of chapter, although not in pdf.
Comments
Post a Comment