Part II – You just gotta bel-ELIF!

--Originally published at TC101 – Peaz Cooper

Well well well! First of all! Ask yourself the following questions:

Do you know the difference between “if”-“elif”-“else” on python? Honey! Where’s my super suit? An where’s my grape juice at? Together we will learn the answers to these awesome and mind-blowing questions!


The “else” statement can be mixed with an “if”statement, since “else statement” contains the block of code that is executed only if the conditional expression in the “if” statements solves to values “0” or a “false” value.


The elif Statement

The elif statement allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.

Similar to the else, the elif statement is optional. However, unlike else, for which there can be at most one statement, there can be an arbitrary number of elif statements following an if.


If you follow these steps you’ll be coding like a bawse in no time!!!

#PeazCooperOut #TC101


Part II – Use of the Conditional “if”

--Originally published at TC101 – Peaz Cooper

Well well well! Second of all! Ask yourself the following questions:

Do you know how to use the conditional “if” in your code? Do you have a knee pain? Maybe some sore throat? Together we will learn the answers to these awesome and mind-blowing questions!


Our life is made by decisions we take day after day, and our code is not an exception! A decision on our program is used when there are a set of actions that depend on our variable’s value and some of these need more information on order to be functional. Thankfully Python has the “if” statement that helps us to make a decision way simpler on our awesome code

n = input("Integer? ") #Pick an integer.  And remember, if raw_input is not supported by your OS, use input()
n = int(n) #Defines n as the integer you chose. (Alternatively, you can define n yourself)
if n < 0: )
    print ("The absolute value of",n,"is",-n)
else:
    print ("The absolute value of",n,"is",n) 


Here is the output from the two times that Mike Steinberg this program:

Integer? -34
The absolute value of -34 is 34

Integer? 1
The absolute value of 1 is 1

What does the computer do when it sees this piece of code? First, it prompts the user for a number with the statement “n = raw_input("Integer? ")“. Next it reads the line “if n < 0:“. If n is less than zero Python runs the line “print "The absolute value of",n,"is",-n“. Otherwise python runs the line “print "The absolute value of",n,"is",n“.

More formally, Python looks at whether the expression n <

Continue reading "Part II – Use of the Conditional “if”"

Reading and Writing! – Basic Ones

--Originally published at TC101 – Peaz Cooper

Well well well! First of all! Ask yourself the following questions:

Do you know how to read on python? Maybe writing in python? In cChinese Japanese? Together we will learn the answers to these awesome and mind-blowing questions!


The syntax is pretty simple; again we have read me and we’re gonna open our new example filled text

readMe = open(‘exampleFile.txt’)

What do we want to do with it? What are our intentions and that’s going to be our for read and then we can go ahead and actually do ” .read “and that will actually read the file into that variable and now we can do print “read me”.

readMe = open(‘exampleFile.txt’,‘r’).read()

print(readMe)

So we can save and run that and you can see that our output is indeed that information.

Check out this YT video for a detail explanation: https://www.youtube.com/watch?v=YV6qm6erphk


If you follow these steps you’ll be coding like a bawse in no time!!!

#PeazCooperOut #TC101


Froot Loops! – While & For Loops

--Originally published at TC101 – Peaz Cooper

Well well well! First of all! Ask yourself the following questions:

How can you create a function on python? How can I call it? Why DC Comics doesn’t know how to make good movies? Is it weird to call my function Martha? Together we will learn the answers to these awesome and mind-blowing questions!


In Python 3 there are two types of loops; there is the “for loop” and “while loop” and this one have very similar results and can be used alternately and it works the same way. The use of these loops depends mainly on the programmer preference. Some surveys of python have already stated that the “for loop” is more efficient than the while loop, but as far as I can tell is not always effective.


Let’s start with the While loop: While something is the case, do the following block of code (Sentdex Youtube Tutorials)

screen-shot-2016-09-14-at-23-28-44

As we can see now we have to specify the terms of the while statement:

  • While the condition variable is less than 10 the condition variable will be printed out
  • After printing out the first condition it automatically adds 1 to the current condition.

For loop:

The “For loop” is the idea of a loop with certain commands like in an instruction manual. This loop is used for tasks that have uncertain time frames (if we can call it that way). Once again this example is brought to you by Sentdex Youtube Tutorials.

screen-shot-2016-09-14-at-23-39-36

As I said before this loop can be used for the exact purposes as the while loop.

For further information about this topic be sure to check out this YT channel about Python Basics: https://www.youtube.com/playlist?list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M


If you follow these steps you’ll be coding like a bawse in no time!!!

#PeazCooperOut #TC101


Creating and Calling Functions!

--Originally published at TC101 – Peaz Cooper

Well well well! First of all! Ask yourself the following questions:

How can you create a function on python? How can I call it? Why DC Comics doesn’t know how to make good movies? Is it weird to call my function Martha? Together we will learn the answers to these awesome and mind-blowing questions!


The main idea of a function in Python is to assign a set of code and variables to a text. It is however referred as “why you choose to write and save a program, rather than writing out the entire program every time you want to execute it.” by the Python guru Sentdex, and personally, I think there’s no better example of it.

1) To begin a function: you define the function by using the keyword “def” that stands for “define”.

     def

2) Naming the function as you pleased, but you have to be careful when naming the variable and the function (try to use names that you know you will remember).

     def example

3) The keyword def should be followed by your function name (check out step #2)  and a parentheses ” ( ) “. YOur function may need parameters, and they should be placed inside of the parentheses. The double dot sign ” : ” needs to be put on the end of the parentheses in order to say “here’s where it stops”.

     def example ():

4) If you want to run the code you’ll see that nothing happens! And please do not panic cause it’s otganic. In order to run it you must type print a value. In this example I’m printing a basic function (z=3+1). Later all we need to do is to close again by using “print”.

     def example ():

   

Continue reading "Creating and Calling Functions!"

Hello World​! – Print

--Originally published at TC101 – Peaz Cooper

Well well well! First of all! Ask yourself the following questions:

Do you already have a “.py” file? No? Do you want one? Wanna create one? Why I never answered the duck question? Together we will learn the answers to these awesome and mind-blowing questions!

Since we are both new in python (at the moment) we need to start with the basics! The “Hello World” is a very common thing while learning this new programming language. I’ve always thought that the best way to learn something is to go step by step, even if it takes you way more time than the average student, you need to feel confident about what you have learned.


How to do it?

1) In order to print “Hello World” you just need to type:

1

2) In order to write something into your program you must use “input” this means that the code will print what the user inputs… literally. Then we can also add a loop… WAIT!! What the heck is a loop dude? Chill mate! A loop is a code that makes the program repeat the same part of the code in a number of times you desire! But we’ll talk about that later.

2


This is the only thing you need to know so far about the “print” and “input” so far…! We’ll make it further in another lesson, but as far as I can tell this is it for now.

If you follow these steps you’ll be coding like a bawse in no time!!!

#PeazCooperOut #TC101


Computer Science I

--Originally published at TC101 – Peaz Cooper

I don’t own a post yet bra… so here’s a tomato salad instead.

1/2 red onion
1 pound tomatoes, about 2 large, 1 red and 1 orange
1 clove garlic
Flaky sea salt and freshly-ground black pepper
2 tablespoons red wine vinegar
1/4 cup extra virgin olive oil
1 red bell pepper, seeded and cut into 1-inch chunks
1/4 pound cucumber (approximately 1/3 cucumber), thinly sliced
1 cup kalamata olives, pitted
1/4 cup fresh dill, roughly chopped
1/4 cup fresh mint, roughly chopped
1 cup crumbled feta cheese

Finely slice the red onion and put the slices in a bowl of cold water while cutting up the rest of the vegetables, 10 to 15 minutes. Cut the tomatoes into bite-sized chunks. Drain the onion and pat dry.

Place the garlic, a pinch of salt, and the vinegar into a large mixing bowl. Drizzle in the olive oil while whisking.

Add the red onion, red pepper, cucumber, olives, and herbs and let marinate for 10 minutes. Add the tomatoes and feta, and toss gently to combine. Add salt and pepper to taste.

Lift out of the bowl with a slotted spoon, leaving juices behind. Place on a large platter and serve immediately.