Lesson 18

In this lesson, Mr Shaw introduces the idea of creating one’s own functions. Fortunately, I have plenty of experience with this and this exercise fazed me not much at all. It takes a moment to get my bearings considering what gets passed through to the defined functions, but it’s really not bad overall. I do see the difference again between Pythons 3.3 and 2.7 again, though, in the way that the arguments are inserted in a print statement via the %r rather than just exiting briefly out of what is being printed and just throwing the variable.

3.3 (what I am used to):
print(“The variable goes here:”, variablename,”.”)

2.7 (LPTHW)
print “The variable goes here: %r.” %variablename

Passing the parameters from the command line as arguments into the defined functions seems to make sense! **(Edit: nothing is passed from the command line to run the program, here. The arguments are defined within the program, not without.) Since a function just does whatever you tell it to (I suppose the same could be said of literally anything you punch into a future program), its structure and formatting does not elude me, especially since we made lots of them when I was knee-deep in 3.3.

And how exciting! He has a big red warning, “don’t worry if you are confused,” well, I am not! Yay! I know I will keep having other troubles down the line, but this one is pretty ok!

The Common Student Questions area advises me to try to break if it I seem bored 🙂 so that is what I did! I passed an argument into a function without using it in that newly defined function, and it wigged out – perfect! I don’t think 3.3 cared if you used the parameter/arg/var passed in, but 2.7 does, and that is sensible and easy to synthesize.

Advertisements

4 thoughts on “Lesson 18

  1. The way you broke the function reminds me of one of the differences between C and C++, where in C++ you can define a variable and not use it and only get a compiler warning, whereas in C it’s treated as an error. At least, in VS2010 it is :).

      • Ah sure!

        For example, if you made this:

        void foo()
        {
        int bar;
        }

        C++ would give you a compiler warning about initializing but not referencing a variable, whereas C would treat it as an error. You’d be able to compile and run the above code in C++, but not in C. This is with Visual Studio 2010 specifically; I’m not certain about other compilers.

  2. Pingback: Lesson 19 | Rachel Learns to Code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s