Pages

Wednesday, January 24, 2018

Control Flow Tools for Python

With the inclusion of strings into our knowledge of Python we can now begin to use tools within Python to not just calculate arithmetic's but use statements to solve on its own. We will begin with the two basic statements "If " and "For", then in a follow up blog we shall work into the Range functions  as well as break, continue and else statements.

If Statements 


One of the most well known statements in python and programming in general is the "If" statements. Providing conditional execution. Pretty simple Right? Lets check it out!

Example of an If statement from the book

Keep in mind at the end of the block you can see an "else:" statement, that will be shown a little later however here is my take on the "If" statements!



The reason why "More" has been printed is because of 20 being greater than 0, if it was equal to 0 it would print the word "Zero" and if it was 1 the program would have printed "Single". A very good example of an If statement.

For Statements


As stated by Guido " The for statement in Python differs a bit from what you may be used to in C or Pascal. Rather than always iterating over an arithmetic progression of numbers (like in Pascal), or giving the user the ability to define both the iteration step and halting condition (as C), Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence. " (Guido Van Rossum 4.2).  Here is an example from the book of a "for" statement:
The for statement
The program written here tells Python to count how many letter are in the words cat, window, and defenestrate which returned with the numbers 3, 6, and 12 respectfully.
Here is my take on the program :


I tested the books program first to see is if the computer would count from 0 or from 1 and it starts from 1 for python unlike web designing languages. After recreating the books program I put my own words and decided to test a couple of other words for fun and the program sent me the correct numbers for the words!
We will dive down into the range functions and other tools later, as for now I have a question for everyone again. With the high demand for knowledge of computers, will IT and similar programming jobs take over engineering and other popular jobs that used to be in demand?









2 comments:

  1. Great question. I think there is evidence already that this is happening. Technology is taking over some jobs. In fact: "Almost half of those currently employed in the United States are at risk of being put out of work by automation in the next decade or two, according to a 2013 University of Oxford study, which identified transportation, logistics and administrative occupations as the most vulnerable" (Jones). That being said, we are still seeing growth recently in the job sector for people. According to Michael Jones, an assistant professor in economics at the University of Cincinnati, "the U.S. economy added 2.7 million jobs in 2015, capping the best two-year stretch of employment growth since the late 1990s, pushing the unemployment rate down to 5 percent" and he doesn't believe this will slow any time soon. I believe there will always be demand for PEOPLE in jobs, although increasingly an understanding of technology and ability to work with technology will be required in all jobs.

    ReplyDelete
  2. Thank you for the reply! Yes the demand in technology has been rising higher and higher in the past several decades! I hope that in the next several years, Computer app jobs will rise in value!

    ReplyDelete