Basic
Programming Blocks
CONTEN TS
VIDEO
Video
woof~
woof~
~
Block
category
Output area
Automatically generated Python script
Coding
area
Python Mode
Mind+ Environment Introduction
\CODE\2.01_PrintHelloWorld.mp
Print Statement
\CODE\2.02_GetUserInput.mp
Get User Input
Conditional Statement
Single branch
Double branch
Multiple Branch
Single Branch Structure
if judgment condition is True:
the number is larger than 10
after executing, continue to execute statement 2
if conditions is False:
the number is smaller or equal to 10
\CODE\2.03_SingleFlow.mp
Single Branch Structure
if…else… Branch Structure
If the expression condition is True:
statement 1 is executed:
the number is smaller than 10
after execution, else is skipped
statement 3 is executed:
done
If the condition is False:
statement 2 is executed:
the number is larger or equal to 10
statement 3 is executed:
done
if…else… Branch Structure
\CODE\2.04_DoubleFlow.mp
Multiple Branches�
\CODE\2.04_MultiFlow.mp
Task 1.1
The random number is also displayed on the serial monitor
if the random number is large:
the serial port monitor displays YES;
else, the serial port monitor displays No;
\CODE\2.05_CompareRandomNum.mp
Task 1.2
The random number is displayed on the serial port monitor
if the number is large, the serial port monitor displays YES;
If the number is small; Display NO on the serial monitor;
If the number equals the set value, OO is displayed.
\CODE\2.06_CompareRandomNum_MultiFlow.mp
Let's continue to study conditional statements
woof~
woof~
~
Comparison Operator
Comparison operator | Explanation |
| equal to |
| not equal to |
| less-than |
| less than or equal to |
| greater-than |
| greater than or equal to |
Boolean Type
\CODE\2.07_BoolTyoe.mp
Boolean variables have only true/false
Logical Operator
Operator | Name | Explanation |
| and | A and B,Only if both conditions A and B are true is the whole condition true |
| or | A or B,If one of the two conditions A and B is true, the whole condition is true |
| not | if the condition is false, the "not" block can make it true |
\CODE\2.08_LoopControl.mp
Loop Structure
Task 2
Please write the code to assess a student’s score.
Set a random score (1~100) and print it on the serial monitor. And comment:
If it’s equal to 100, print “Excellent”;
If it’s greater than 90 (inclusive) and less than 100, print “Well done”;
If it’s greater than 80 (inclusive) and less than 90, print “Good”;
If it’s greater than 70 (inclusive) and less than 80, print “Not bad”;
If it’s greater than 60 and less than 70, print “Nice try”;
If the random number equals 60, print “Interesting”;
If all the above conditions are not met, print “Smile”;
You may add some delay time in the loop to slow down for better observation.
\CODE\2.09_RandomNumInMultiFlow.mp
The previous comparison code can only be executed once per run. You can also write the code in the loop to let the program judge contiguously.
Pay attention to the delay time. Otherwise, the program will run very fast!
\CODE\2.10_LoopRandomNumCompare.mp
A comprehensive example of sound and light cycles
\CODE\2.11_LoopRandomNumOpenLEDBuzzer.mp
In the following example, we may not show the common starting blocks.
Remember to add them by your own!
On the basis of the previous code, please write the code, to achieve the following requirements:
print "Yes", the light LED lamps;
Print "OO", light LED lights, buzzer alarm at the same time;
Print "No", a buzzer alarm.
woof~
woof~
Now we have learned programming basis.
Next time we'll help Bittle do various actions in Mind+