This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
3. Argument Types - Part II | |
Now let's say we want to make sure that the caller always | |
gets a numeric value back, even if the input wasn't of the | |
right type. | |
To achieve that, we need to check the type of the argument | |
that was passed in. If it wasn't a number, we probably | |
shouldn't try to multiply it. We'll just return 0 in that case. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1. Parameters are Local to the Function | |
Each parameter of a function is effectively a variable. | |
As we saw in the previous lesson, it has a name that we | |
can use inside the function to refer to the value that | |
was supplied by the call to the function. | |
Once the function has been called, is that name available | |
outside the function? To test this, first run the code as is. | |
You should see "ERROR: w is not defined". What that means |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
4. After Dark | |
The cost of a Taxi ride varies by time of day (we pay | |
drivers extra to work the night shifts). A flat surcharge | |
of $0.50 is added to cost for any trip starting at 8pm | |
and continues until we hit 6am. | |
Expand your taxiFare function to accept a second parameter | |
called hourOfDay which represents the time of pickup. Add | |
a night surcharge of $0.50 during the appropriate hours, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
5. You've Arrived at Your Destination | |
It's been a late night at the office and the company | |
is footing the bill for your trip home. | |
Use the taxiFare function you've written to set the | |
variable tripCost to the cost of your crosstown ride | |
of 5 miles at 2:00 in the morning. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
2. Looking back at conditionals | |
Last week we saw how using if else statements allowed us to return | |
different outcomes for different scenarios. | |
We also saw how we can use switch statements and ternary operators | |
to write neater code. | |
Perhaps the most difficult part of conditionals are nested conditionals. | |
Let's review this concept again with a simple example. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
2. FizzBuzz Revisited | |
Now that we know more about Boolean operations, let's return to the | |
FizzBuzz exercise and explore it a bit more. | |
We've given you the output we want in console.log(""). All you have | |
to do is provide the code for the conditions that will result in the | |
correct Boolean value for each if statement. | |
Place the right conditions in the right places. Use Boolean operations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Now that we've covered the bare essentials, try rebuilding the | |
factorial() function we've been working on, but this time write | |
it all from scratch. To help you along, here are five questions | |
that you can use whenever using recursion in your code: | |
-What is/are the base case(s)? | |
-What is/are the recursive case(s)? | |
-Have I included any other necessary termination condition(s)? | |
-Do the statements in the function lead to the base case? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Problem 3: Newton's Method | |
def computeRoot(poly, x_0, epsilon): | |
''' | |
Uses Newton's method to find and return a root of a polynomial function. | |
Returns a list containing the root and the number of iterations required | |
to get to the root. | |
poly: list of numbers, length >= 1. | |
Represents a polynomial function containing at least one real root. | |
The derivative of this polynomial function at x_0 is not 0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var contents_article_no = "1234567"; //'[0-9]{7}' | |
var looping = "0"; | |
var BLOGID= "1AaAAU"; //'[0-9][A-Z][a-z][A-Z]{3}' | |
var isblock = false ; | |
isblock = parent.document.getElementById("div_" + contents_article_no).oncontextmenu() || isblock; | |
if(isblock) { | |
document.write("<meta http-equiv=\"imagetoolbar\" content=\"no\">"); | |
document.oncontextmenu = function() { return false; }; | |
document.onselectstart = function() { return false; }; | |
document.ondragstart = function() { return false; }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
FILE_NAME = "1C_ProbA_PartElf_small.in" | |
OUTPUT = "1C_ProbA_PartElf_small.out" | |
def load_file(): | |
''' | |
String -> ListOfInt | |
Open a newline delimited text file and do the following | |
manipulations: |