Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101fall2015/wp-includes/feed-rss2.php on line 8
‘Mastery’ Articles at TC101 Fall 2015 https://kenscourses.com/tc101fall2015 Introduction to Programming Python and C++ Thu, 26 Nov 2015 01:47:28 +0000 en hourly 1 https://creativecommons.org/licenses/by/4.0/ Mastery10 https://kenscourses.com/tc101fall2015/2015/mastery10-6/ Thu, 26 Nov 2015 01:47:28 +0000 http://5nbppkkyj.wordpress.com/2015/11/26/mastery10-2/ ]]> Mastery10Basic output (print) in Python

The main output function is called print(). This function basically lets you make your output look nicer and easier to read.

So you can basically take your input and save it in our variable “n” so you can reuse it using your output function print().

n = input(“Please enter your age: “)

Once we have our input, which is the user’s name. We can take it and print it.

n = input(“Please enter your age: “)

print(n)

But that isn’t too fun since we are basically repeating what the user said. We will put it inside the stringthat restates the obvious.

n = input(“Please enter your age: “)

print(“The user is ” + n + ” years old.”)

This looks better right? The correct answer is no because we didn’t convert our input into a string.

n = input(“Please enter your age: “)

print(“The user is ” + str(n )+ ” years old.”)

Overall, there isn’t much to the print() function, you just have to remember the type of data you are printing and handle it accordingly.

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery09 https://kenscourses.com/tc101fall2015/2015/mastery09-4/ Thu, 26 Nov 2015 01:46:31 +0000 http://5nbppkkyj.wordpress.com/?p=270 ]]> Basic types and their use in Pythonintegers 

Whole numbers from negative infinity to infinity, such as 1, 0, -5, etc.

Integers or any number negative or positive without decimals can be assigned variables. You can name them anything. You can work with integers directly or assign them to variables. By work I mean you can add them, subtract them, multiply them, divide them, use parenthesis which is useful for order of operations and you can also call calculate powers and remainders. Retainers are cool because they are useful for loops and other operations. Power values are cool because they can also be used in square roots. So in a few words, standard math operations with some useful twists.

float 

Float means “floating point number,” any rational number, usually used with decimals such as 2.8 or 3.14159.

When you do math with integers, your computer interprets values as integers so you will never get a float unless you specify it. To specify, you can just add a decimal point or you can write whatever number “n” like this “float(n)”. When you do math with floats, your result will always be a float. It is important to note that when you mix strings and floating points, Python will always return a float. 

You can also turn a float into a integer value using “int(4.0)”

strings 

A set of letters, numbers, or other characters (!,&,%,#). 

Strings are sequential collections, so items in the collections are ordered.

Depending on which version of Python you are using, strings will be inside single(”) or double quotation marks (“”). In Python 3 strings will also be inside quotation marks and those quotation marks will be inside parenthesis. Strings can also be added (like integers and floats) using +’s or commas, this is called concatenation.

They can be assigned as a value to add or print or both. Integers and characters can be converted into strings by using str(). 

lists 

 x=[1,2,3]  

look at the square brackets!

Lists are sequential collections, so items in the collections are ordered.

 Sometimes regarded as the most powerful data structures in Python while simply being sequences of stuff. You can call them “x” or “sushi”, so when you run it its elements will be used. You can evaluate each element of the list by calling x knowing the position of the element you need. You can also change an specific element of your list, mixing data types and putting other lists within your list. Variables are your friend, a new variable “pizza” can refer to your existing variable “x” which has your list and make changes on your elements (as well as other useful things). To copy lists, not refer to them, you can write pizza = x[:]. This specifies which elements you want to have and copies them, this notation is cool because it lets you choose a range (from up to but not including). 

tuples 

Tuples are sequential collections, so items in the collections are ordered.

A list with a fixed number of elements. ie x=(1,2,3) parentheses makes it a tuple.

Tuples are created the same way lists are that is, they are declared like this x=(). In Python Tuples are generally seen as a clean way of storage since they are memory efficient and not adjustable but this advantage can also be seen as inflexible 

dictionaries 

A type with multiple elements i.e. x = {1: ‘a’,’b’: 2,3: 3} where you address the elements with, e.g., a text.

Dictionaries basically bind a key to a value,. One of its characteristics is their lack of order in sorting data, so dictionaries are not sequential collections like lists, strings and tuples. Some of the possible values in dictionaries can be range from lists to functions. To create a dictionary you can do the following x = {}. To reference a value in the dictionary you can print it by calling they key so 

using the example above, if you print x[1] you will get the value of the key 1 which is “a”.

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery28 & Mastery29 https://kenscourses.com/tc101fall2015/2015/mastery28-mastery29/ Thu, 26 Nov 2015 01:22:16 +0000 http://5nbppkkyj.wordpress.com/?p=195 ]]> User input (text based) in Python (basic) and Validated user input in Python

One way to have data in your code is to get it from external sources such as databases, another computer, the Internet, etc. The options are endless(sort of). Depending on what your code is about you will find that user input is quite valuable if you know what to do with it, we shall see more about this later on. First, we need to see how to get it.

Python makes this super easy for you because it has a built-in function which is unsurprisingly called input.

To declare an input you just add a parenthesis and type your prompt. In the example below I ask for someone’s age or you can get more complex data by creating lists or dictionaries with the input.

n = input(“Please enter your age: “)

The computer kind of replaces “Please enter your name:” with whatever the user writes, which is a prompt string. And when the function is evaluated the input is shown. Remember that whatever the user types, even if it is a number or a character, will ultimately be a string. If you want to use it in any other way then you would use other functions such float or int to modify it.

So in the code above, the variable n is replaced by whatever the user inputs, according to my example if I were to use my short program n will become my age as a string. The next piece of code shows you how to convert it into an integer using the int function.

n = input(“Please enter your age: “)

age = int(n)

I simply created a new variable called age and the value of my variable is mainly the user input but the function int before the name of the variable changes my age as a string intomy age as an integer. Allowing me to work with it.

So what happens if the user input does not match what you’re asking for? You validate it using =.

n = input(“Please enter your age: “)

if n == int:

print(“You look younger!”)

else:

print(“Not a number!”)

Conditionals are useful for this. My code above validates their input by asking whether n is an integer if it is not it prints “not a number” and if it is an integer it prints a very fake compliment.

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery15 & Mastery16 & Mastery17 https://kenscourses.com/tc101fall2015/2015/mastery15-mastery16-mastery17/ Thu, 26 Nov 2015 01:22:14 +0000 http://5nbppkkyj.wordpress.com/?p=184 ]]> Conditionals are generally a way to check something. The classic “if” example is easy to understand. The syntax helps you understand it a bit. A normal if statement would look like this:

if(condition):

do something
Let’s see an example with food because I’m hungry. My code will basically ask if the food is ready by having the user input dictate its state of readiness (that explains the variable name) and then my conditional if checks the data to perform an action, it prints “yay” if the food is ready. But the operator = helps me know if the user input is right. We can evaluate other values by using other operators such as < > to compare values.
readiness = input(“Is the food ready? “)

if(readiness == “yes”):

print(“yay”)
We can also combine two conditionals in an if statement by using the Boolean operation and. I added a new value which is my food temperature so my conditional are always met and my if statement will work.
readiness = input(“Is the food ready? “)

temperature = input(“Is the food hot? “)

if(readiness == “yes”) and (temperature == “yes”):

print(“yay”)
The same can be done with the operation or. What or does is it basically combines two conditionals and the action will be executed if either conditions are met. So in this case it doesn’t matter if our readiness or temperature are not hot or ready if one of them is true our action will be executed.
readiness = input(“Is the food ready? “)

temperature = input(“Is the food hot? “)

if(readiness == “yes”) or (temperature == “yes”):

print(“yay”)
So my values were checked and my program acted accordingly. But what if the value is not what I asked for? There is an operator called else that solves this problem. In this case, else doesn’t have to include a condition because we don’t care about anything else, we just want to have our food right? All I have to do is write else below my if statement without an indentation and tell my else what to do.
readiness = input(“Is the food ready? “)

if(readiness == “yes”):

print(“yay”)

else:

print(“hurry up, I’m hungry”)
There is another conditional that is a mixture of else and if and it must be typed between your if and else. It is called elif. It basically sets up another conditional so it is a lot more like it but it is still like else.
readiness = input(“Is the food ready? “)

if(readiness == “yes”):

print(“yay”)

elif(readiness == “yep”):

print(“yay”)

else:

print(“hurry up, I’m hungry”)

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery06 https://kenscourses.com/tc101fall2015/2015/mastery06-3/ Thu, 26 Nov 2015 01:22:08 +0000 http://5nbppkkyj.wordpress.com/?p=176 ]]> Install Linux on their own computer.

These are some reasons why people install Linux:

-it’s free

-It is customizable so you can tailor it to suit your preferences

-It forces you to learn more

-It is very difficult to get malware, mind you it remains a possibility.

-It is not run by corporate interests so you can do whatever you want without having the fear of being spied
Before we get to the installation process, you need to know 2 things. These can save you time an resources in case installing Linux backfires on you.
Knowing which computer model you have

A simple google search should tell you if any poor soul had any problems installing Linux. That simple search could show two things to you. Installing it will be impossible so you shouldn’t even try, or installing it will be a pain in the rear but you will learn a lot. At the end, it’s up to you but you have been warned.
Backing up your data

As a “something goes horribly wrong” prevention measure, you should have a sub with all of your information(or the most important) so you don’t lose anything in the installation process.
You then choose a Linux distribution, usually referred to as distros. Distros gives your computer specific looks, a custom feel, default applications, among other stuff.
From here, the process can vary a lot. Some popular and “easy” distros are Fedora, Linux Mint, and Ubuntu. I will show you how to install Ubuntu 14.04, which is similar to Linux Mint.

First thing you need a USB drive a 1GB to a 2GB should be enough. This will contain your Linux distro so you can boot it from there.
Ubuntu is pretty cool because it has a simple installation wizard with some screens that will ask you things like your time zone, keyboard layout, username, password, and most importantly your partitioning setup. (Your partition can be done automatically by Ubuntu in several ways, this up to you but doing your research beforehand will help.
Once the installation is properly handled with the help of the wizard (disclaimer: it’s not am actual wizard) you can check out some of the default programs or browse the web. Ubuntu and other distros have a simple set of basic, easy-to-use configuration tools but overall they automate a big portion of it.

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery04 https://kenscourses.com/tc101fall2015/2015/mastery04-4/ Thu, 26 Nov 2015 01:22:06 +0000 http://5nbppkkyj.wordpress.com/?p=177 ]]> Submit work via Blog RSS and GitHub

RSS stands for Really Simple Syndication or Rich Site Summary

Subscribing to a website RSS removes the need for the user to manually check the website for new content. Instead, their browser constantly monitors the site and informs the user of any updates. The browser can also be commanded to automatically download the new data for the user.

RSS is basically an structured XML document that includes full or summarized text along with other metadata such as published date, author name, etc. RSS feeds can be read by using programs called “RSS reader”, “feed reader”, or “aggregator” which can be web-based, desktop-based, and even mobile-based.

In orfer to Submit your work you first have to be registered to Ken’s page. What this does is it adds your blog to the RSS feed on Ken’s page. Go to tags and add an specific keyword. For example, if you have done a WSQ you have to tag your blog post in this “tags” section and specify which WSQ it is.
GitHub

GitHub provides you with a user interface app that lets you upload your work to github. You can also use git in the command line but this is way easier. So too upload your work to github, download the desktop application. It is available at https://desktop.github.com. Once you have downloaded and installed github open it and create a repository. A repository is a digital directory or storage space where you can access your project, its files, and all the versions of its files that Git saves. So drag your files to the github window. GitHub will ask you if you would like to create a new git repository Click on create and add

All Git repositories are based on commits, commits are snapshots of your code at a point in time. You need to make at least one commit before you can push your code up to GitHub.com.

Click create and add

Go to the Changes tab and click Commit to create your first commit. Everything you change your files you will have to make a new commit, this will help you with version control.

Make as many commits as you like locally. No one but you can see those commits until you push them to GitHub.com.
Click the “Publish” button in the upper-right corner and GitHub Desktop will ask you what kind of repository to create:
Public repository — Anyone can see this, but you choose who can make changes) to it. You can
Private repository — only you can see your repository but You have the option of choosing who can see and commit to this repository by adding collaborators.

So now your repository is saved remotely on github and locally on your computer.

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery08 https://kenscourses.com/tc101fall2015/2015/mastery08-4/ Thu, 26 Nov 2015 01:22:05 +0000 http://5nbppkkyj.wordpress.com/?p=178 ]]> The Zen of Python

The Zen of Python is an Interesting easter egg in Python.

Originally written by Tim Peters in 2004, it as an informational entry number 20 in Python Enhancement Proposals
You can find it by entering the statement “import this”
I shall comment on a few of them because I think they are open to interpretation.

The Zen of Python

Beautiful is better than ugly.

-Beauty is subjective and ugly is too extreme, so whatever floats your boat is fine really. When I say ugly is too extreme I mean that when something is obviously ugly you can make it look better while improving its functionality.

Explicit is better than implicit.

Simple is better than complex.

-when something. Is simple it is also easily knowable.

Complex is better than complicated.

Flat is better than nested.

-I read that some people may get confused and think of the wrong kind of nesting, not the bird kind of course. It refers to block nesting, for a lot of reasons it usually seen in a negative light since it leads to complex code.

Read more here:

https://en.wikipedia.org/wiki/Cyclomatic_complexity

Namespaces are great as they help organize code to reduce complexity.

These 2 are complimentary as they are both about reducing code complexity.

Sparse is better than dense.

-this may refer to a general minimalism. Minimizing your depth of nesting of control structures, the number of lines or length of code, token count, character count, parameters, variables, looping instructions and conditionals. Minimizing at our level of programming may be risky for example, having long names for variables can actually be helpful so you just have to be careful. ,m

Readability counts.

-Some may say this is what makes organizations choose Python but who knows.

Special cases aren’t special enough to break the rules.

-Everything is an object

Although practicality beats purity.

-rules can be broken if you need to. For example circular imports:

They’re not always a bad thing. In many cases you only have to import the module not from the module.

Errors should never pass silently.

-silent errors can wreck you and make you blame the users.

Unless explicitly silenced.

-Errors can be addressed in creative ways.

In the face of ambiguity, refuse the temptation to guess.

-self explanatory I think.

There should be one– and preferably only one –obvious way to do it.

Although that way may not be obvious at first unless you’re Dutch.

– Guido needs more credit.

Now is better than never.

-Just don’t wait, it’s not worth it.

Although never is often better than *right* now.

If the implementation is hard to explain, it’s a bad idea.

-better avoid it than do something without knowing.

If the implementation is easy to explain, it may be a good idea.

-you should also avoid extremely simple stuff.

Namespaces are one honking great idea — let’s do more of those!

(Where is number 20? Is it a formatting character? Maybe a new Line?)

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery07 https://kenscourses.com/tc101fall2015/2015/mastery07-5/ Thu, 26 Nov 2015 00:34:38 +0000 http://5nbppkkyj.wordpress.com/?p=170 ]]> Use of comments in Python

It is said that comments tell you why and your code tells you how. When you code, you are telling your computer what to do using just instructions. It is not a human that needs to know the actual reasons why it works but you do have to keep your audience in mind.

Depending on what you are coding, you will find that your use of comments will change so at times they may serve as warnings other times as simple explanations.

In several tutorials or learning resources you will find short comments explaining what does what, as a beginner they will help you understand how the code works and with enough practice you will eventually learn why it works.

Are comments crutches?

This follows the idea that your code cannot be made more readable with more comments. Comments on our programming level are crutches that we will eventually stop relying heavily upon. So it is important to note that your code does not need comments. You should only use them when it cannot be made easier to understand.

Your audience

Your comments will most likely be read. By others, whether that’s a coworker or future you. If you are like me, when you go back to old code (and you remember nothing about it) comments will help you understand it faster.
Regardless of whom is it aimed at, you should avoid repeating things that are obvious in your code. There is an exception to this, when your code looks obvious but it’s not comments are the option. For example, if you’re multiplying a variable by some an arbitrary number, explain why you’re doing so. If you trim something specific from a string before returning, put a comment in explaining why so that the person reading doesn’t have to spend time tracking it down themselves.

How to comment
Another use of comments is to give an overview of what is going on, as opposed to explain each step.
This code is what your comment described, but is commented with higher-level descriptions of what’s going on rather than a line-by-line description of the code.

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery03 https://kenscourses.com/tc101fall2015/2015/mastery03-2/ Fri, 18 Sep 2015 20:33:39 +0000 http://5nbppkkyj.wordpress.com/?p=103

]]>
https://creativecommons.org/licenses/by/4.0/
Mastery02 https://kenscourses.com/tc101fall2015/2015/mastery02/ Fri, 18 Sep 2015 20:20:03 +0000 http://5nbppkkyj.wordpress.com/?p=100

]]>
https://creativecommons.org/licenses/by/4.0/