Personal recommend : practice is key
Recommend use : IDLE, Pycharm
In the next few days I would teach you:
- Learn to develop and reason about algorithms
- After that you can be able to program them in python
- And you would start to understand the limitations of algorithms
The skill for this days you need to master:
- Python programming
- Algorithm design and analysis
- The thought of problem solving
What is an algorithm?
Thinking: 653 + 274, how we calculate this equation?
The algorithm is take your way into code and calculate automatically and give you the result
Hence we can transfer this Question into a computational problem:
Input: two numbers n and m
Output: the sum n+m
The process is:
- you give the input n and m to ‘computer
- the ‘computer’ execute the algorithm according the number you input
- after ‘computer’solve your problem and then return the output to you
an algorithm must:
- have input and output
- finiteness: must always terminate
- definiteness: each step sufficiently well defined
- effectiveness: ‘computer’can perform each step
try some simple exercise:
- Input: 3, output: 3
- Input: 1.7 + 0.9, output: 2.6
- Input: round(1.7+0.9), output: 3
- Input: round(1.7+0.9) -1, output: 2
If you input wrong like this:
Input 1.7 0.9+, it would return Error: invalid syntax
Know the types:
Int , float, string
Eg. 3.7 is a float, 3 is an int, ‘3344’is a string
know how to convert between object types:
int(x), float(x), str(x)
eg. Int(3.7)=3, float(3)=3.0, str(3.0)= ‘3.0’
know operators for numeric expressions
+, -, *, /, //, %, -x, x**y
Take some examples:
- 7//2 = 3
- 7 % 2 = 1(% means mod)
- 2**3 = 8
Know the precedence between operation:
4. Lowest: +,-
5. Medium: *, /, //, %
6. Highest: **
Take an example: 3 + 10*2**3%5-2
Step1: 2**3 = 8
Step2: 10*8 = 80
Step3: 80%5 = 0
Step4: 3+0-1 =1
now let me take you to know ‘variable’:
We can assignment a value to variable:
Eg. Input: X = 17*2 input : x ,‘computer’would output: 34
Certain keywords are reserved by the python and cannot be used as names:
Such as: False, None,True,if,import,not,try,while,with,yield,if,is,lamba,elif,and,as…
Now let me take you to know’function’
Eg. Round(2.7)=3, abs(-100) = 100, max(17, 20, 100) = 100
More functions available in modules:
So you need to import module like lise:
Eg1. ‘From math import sqrt’and then you can use sqrt(2)=1.414…
Eg2. ‘from math import floor’and then you can use floor(19.7)=19
If you don’t know the meaning of one function you can use function‘help()’
Eg. Input : Help(pow), the computer would return the meaning of pow and how to use it.