Boston Python Workshop 6/Friday/CodingBat Using Codingbat: Difference between revisions

imported>Jesstess
No edit summary
imported>Adamf
 
(7 intermediate revisions by one other user not shown)
Line 1:
We are going to use a website called [http://codingbat.com/home/bostonpythonworkshop@gmail.com/PythonIntro CodingBat.com] to practice Python throughout this workshop.
 
Before you do the CodingBat questions for the Friday tutorial, let's walk through how to use CodingBat.com with an example.
Line 11:
We like CodingBat because it gives you immediate feedback on how close your function is to being correct.
 
Let's walk through an example:, the [http://codingbat.com/prob/p216579 the sumTwoNumbers] exercise.
 
If you visit that exercise web page, this is what you'll see:
Line 23:
This screen:
# describes the problem (write a function to add any two numbers together)
# shows you some of the inputs that CodingBat will use to test the function you've written, and the outputs that CodingBat expects to see returned from your function for each input.
 
The inputs are the values in the parentheses, and the expected output is the value pointed to by the arrows:
Line 31:
 
 
If you simply click "Go" without typing anything in the box, CodingbBatCodingBat gives you an error on the right hand side of the screen:
 
 
Line 37:
 
 
Let's add some code. The '''function signature''' (the <code>def sumTwoNumbers(first, second):</code> part) has already been written for you. You'll write the rest of the function -- remember to indent everything inside the function, and remember to <code>return</code> your result instead of <code>print</code>ing it!
 
 
Line 43:
 
 
Hmm. I've got one correct and two wrong. MaybeOh! insteadI ofsee - I typed in <code>returnfirst</code> twice, when instead I should usehave used <code>printsecond</code>?:
 
 
[[File:Cbat_print.png|border|center]]
 
 
That's not it. CodingBat problems always want you to use <code>return</code> in your functions. Oh! I see - I typed in <code>first</code> twice, when instead I should have used <code>second</code>:
 
 
Line 55 ⟶ 49:
 
 
Great! All the tests are green, so we know that we've done this problem correctly and can move on to the next one.
Great!
 
IWhat canCodingBat checkis thisdoing by typingis the same as when you write a function intoin your text editor or at the commandPython prompt and then run it a few times, like this:
 
 
What CodingBat is doing is the same as when you write a function in your editor or at the command prompt and run it a few times, like this:
 
<pre>
awf$ python
Python 2.6.1 (r261:67515, Aug 2 2010, 20:10:18)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def sumTwoNumbers(first, second):
... return first + second
Line 78 ⟶ 65:
</pre>
 
Perfect!
 
Now that you are a CodingBat master:
 
<div style="font-size:125%">[http://codingbat.com/home/bostonpythonworkshop@gmail.com/PythonIntroFriday Now&raquo; weClick can move onhere to completing tonight's practice problems &laquo;]</div>
Anonymous user