Learn Programming in Python from Scratch More Advanced Stuff

in #science7 years ago (edited)

In this post we will learn something useful :).

Before proceeding with it, we need to know our basics (primitive types and the concepts of variables in Python),
if you have to remind yourself consult: https://steemit.com/science/@ai-enthusiast/learn-programming-in-python-from-scratch-getting-started

Learning objectives

  1. Get familiar with Control Flow (Get to know different types of loops and if-else statements)
  2. Put it all together, in the example which we'll use later to build upon

Thanks to omarf, who suggested changes :D

Control Flow:

Understanding Control Flow(order in which the commands are executed) is essential to programming. There are just a few ways to change it. However the way they're combined, leads to complex programs that are actually useful :D. Without these ways, order in which commands are executed is from the first line up to the last one.

Operators:

Before we proceed, I must point some other things in Operators. You can also do this:
operat.png
operats.png

Now, let's continue:

Loops:

When you have a piece of code you want executed multiple times, instead of copy/pasting the code, which makes it hard to read and prone to error, you would want to use loops. There are two types of loop, FOR loop (which you will use usually when you know in advance what number of iterations(passes through a loop) will be there, and WHILE loop (which will run, until some condition is met). Anything you write inside of a loop is considered it's 'body';IF-Else.png
loops.png

Scope

Make special attention to the indentation. In Python, if you indent something that means it belongs to the outer scope (area in which it is visible).
scope.png
In other programming languages you wouldn't be able to acces a Variable defined in some other scope (you can, but not directly). In Python you can access it, basically directly.

IF-ELSE:

When you want you your program to have branches, meaning only one branch(path) gets executed, you would use IF-ELSE statements. Statement number == 1 returns a Truth value (True or False). If it returns True the body of the IF gets executed. If it returns False, body of ELSE gets executed.
IF-Else.png
There's also an ELIF statement, which tests another condition if the condition in IF statement is not met.
ELIF.png

Putting it together:

We will write our first complete program. Let's say we're teachers and we want to review our students based on grades.
If they got a good grade, we will encourage them. If they got a bad one, well...
program2.png

out.png

Sucks to be Mya :D

See you in the next post.

Sort:  

How is this learning from scratch? Control flow, operators, scope are all concepts that need more careful, in-depth explanations. One needs to start with simpler examples as well. Also, in the beginning of the post, you should state what exactly people will learn by the end of the post (the learning objectives). I am not your boss or your teacher, but I am just trying to give you helpful advice here. Hope you don't mind and understand my point.

you are right, applying your advices will make this post really amazing

I understand the point you're making. I'll change the post to include learning objectives. Thanks for your feedback. This is a continuation to the first post. in which I started from the beginning. This is how I was taught, I just like that way. :D

Hello @ai-enthusiast! Would you consider being my occasional coach/consultant on Python learning? I'm an experienced programmer; but have not yet learned Python. I recently decided to do so in order to do some 'fishing around' in the Steem block chain and to prepare for another application which I will mention shortly.

I have set up a nice IDE and began following a Udemy course, which is moving too slowly for my taste. So I'm planning to more or less set up my own learning program (perhaps involving converting some of my R-language programs to Python), and for that I will need a coach when I got stuck at certain points.

Unfortunately, I do not have much time for this project because I must give higher priority to learning technical details about the Bancor protocol, and it's code which is Etheruem's Solidity. (I really hate the idea of investing valuable time in learning a language that has only one environment in which it is useful; but I have no choice because only the Bancor protocol is offering the application that is of concern.)

This is the application where you can buy and sell your token in an environment where there is no market maker. According to the SMT Whitepaper, this application is also going to be part of the SMT software, so once that software becomes available I expect I would be getting out of the Ethereum environment and coming over to Steem via Pytthon.

So, let me know if you would be available to help me. I will be happy to negotiate direct payment to you in SBD, BTC, or LTC.

P.S. I am now Following you,so don't quit Steemit just yet!

I messaged you via steemit.chat

I have have no luck trying to find people at Steemit.chat (they tell me to go there and when I do they are 'not found'). Anyway, I will try once more! Thanks.

PS. Can I invite you to be the first visitor to my brand new Discord Channel ("Smart_Tokens")?

my id on steemit.chat is ai.enthusiast

Coin Marketplace

STEEM 0.23
TRX 0.26
JST 0.040
BTC 98185.12
ETH 3486.20
USDT 1.00
SBD 3.27