Programming
Photo by Chris Ried on Unsplash
Programming Environment
In this class, we are going to use Python3 as the compiling language. The link below will lead to an online python3 compile page. You can run your programs there.
https://www.tutorialspoint.com/execute_python3_online.php
Pseudocode
Pseudocode is an informal high-level description of a computer program or algorithm. It is written in symbolic code which must be translated into a programming language before it can be executed.
For example:
(Pseudocode)
if today’s weather is good
we can go to the zoo
Else
we stay at home!
In the pseudocode above, If the weather is good, we can go to the zoo, otherwise, we stay at home. we demonstrate our logistics into programming form. This high-level logistic thinking can transfer to real code if you know the right syntax. The code below will compile the pseudocode to real code, you can copy and paste to run and see what is happening here.
(Real python3 code)
Always remember indentation in python is very important. After you run the code above, please try to change”weather=’good’ ” to something else, what will happen? I wish you understand the idea here, let’s learn the first statement for today.
First Statement
< print(“ ”) >
please open the online compile environment we mention before
The print line should shown
Try to switch “Hello World” to something else and push execute button
What will happen?
Second Statement
<
if (condition) :
#block of code to be executed if the condition is true
else :
# block of code to be executed if the condition is false. >
As we mentioned above, the if-else statement uses very frequently. if you want to master programming skills, you have to know how to use it wisely. The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. Can you translate the following programming language into a pseudocode?
Third Statement
In python, a for-loop (or simply for loop) is a control flow statement for specifying iteration, which allows code to be executed repeatedly. Various keywords are used to specify this statement.
what’s the answer here? Can you make a guess?
Forth Statement
for-loop with range. range(min_value, max_value) Another use case for a for-loop is to iterate some integer variable in increasing or decreasing order. Such a sequence of integers can be created using the function. Let’s see an example
in this example, it will print 2 output, both i and i*i. The i value starts at 5 and ends at 10. This is a basic math question, do you know what is the last output?
Quiz Time
- Please use pseudocode to explain the following code below and sent it to me in the following link : https://forms.gle/HwtQVo71hfQtKZMN7
2. Convert pseudocode to real code and run it though environment:
If student’s grade is greater than or equal to 60
- Print “passed”
else
- Print “failed”
3.
submit link: https://forms.gle/HwtQVo71hfQtKZMN7