Prepare for trouble! And make it double!

Prepare for trouble and make it double!

Topics

  • Zen of Python
  • Use of loops with while
  • Importing and using modules/libraries
  • Use of conditional “if”
  • Use of conditional “else” (and elif)

 

This blog is made by Juan Montero and Daniel Arrieta #TC101

 

Zen of python

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
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.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!

 

First of all what is zen of python, it is recognized as how coding in python should be, since we don’t really understand we use it already, for example on the simple is better than complex, just as our last blogs that is just, print, or calling a function, etc.

whoa

This is our expression after knowing the Zen of python.

https://www.python.org/dev/peps/pep-0020/#id3

 

Use of loops with while

 

We already know the command while, but this comes a rather.. funny exception with loops, making it repeat until all the criterias are accomplished, let’s put it easier.

while-expression

http://www.python-course.eu/python3_loops.php

So until the condition is satisfied it will keep running until it is realized, this is the explanation that, only Ken would read (100% sure about this), so the coding would look like this( what most students are looking at this time). #python3Loops

while-coding

Use of conditional “if”

 

This command is one of the most important commands in programing since this conditional tells the computer what to do when we face a certain situation.

fuck-yourself

When someone is trying to interact with a user through a program there could be many outcomes. Because every person has individual thoughts and opinions, so IF a person do or say something you will react in a certain way. (See what I did there?). Therefore, when you use “if” you have to tell the program what should it expect from the user, and what to do once the condition has been accomplished.

The conditional if, is used in open questions where the user can change its answer for example Nationality, or age or favorite color.

http://www.python-course.eu/python3_conditional_statements.php

#Trilingual_Is_Good #Friendship

conditional-if

Use of conditional “else” (elif)

After using the conditional “if” it could be that the user doesn’t do as you expected… That could be pretty bad if it wasn’t for “else” the other part of the “if” command. this command could be used when the user is trying to annoy your baby-program, you could avoid those trolls.

 

You use “else” after the command “if” this to complement the code and give more options to it; because,  when there is no food in your fridge, you simply don’t stand there staring at an empty fridge… Or at least I hope so… When there’s no food you go to the supermarket or just order food on your phone. If there’s food on the fridge, you eat, else, go to the supermarket, Yep it is really that easy, mate. and on code it looks like this

  • if condition1 :
indentedStatementBlockForTrueCondition1
  • elif condition2 :
indentedStatementBlockForFirstTrueCondition2
  • elif condition3 :
indentedStatementBlockForFirstTrueCondition3
  • elif condition4 :
indentedStatementBlockForFirstTrueCondition4
  • else:
indentedStatementBlockForEachConditionFalse

r-u-srs

#”Fun”

But on the code it looks easier

elif-code

tip, check comments so you can see why we use different expressions.

 

http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/ifstatements.html  

https://docs.python.org/2/library/random.html

 

Importing and using modules/libraries …

 

TO BE CONTINUE…

2 thoughts on “Prepare for trouble! And make it double!

  1. This is one of the longest and greatest post I have seen, and I have seen like two or three; so I’ve seen some long stuff. You cover prefectly the topics you needed to cover. I am going to start calling your blog Bing Bong, because is the ideal friend.

    Like

Leave a comment