踏进python世界的大门

Personal recommend : practice is key
Recommend use : IDLE, Pycharm

In the next few days I would teach you:

  1. Learn to develop and reason about algorithms
  2. After that you can be able to program them in python
  3. And you would start to understand the limitations of algorithms

The skill for this days you need to master:

  1. Python programming
  2. Algorithm design and analysis
  3. 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:

  1. you give the input n and m to ‘computer
  2. the ‘computer’ execute the algorithm according the number you input
  3. after ‘computer’solve your problem and then return the output to you

an algorithm must:

  1. have input and output
  2. finiteness: must always terminate
  3. definiteness: each step sufficiently well defined
  4. effectiveness: ‘computer’can perform each step

try some simple exercise:

  1. Input: 3, output: 3
  2. Input: 1.7 + 0.9, output: 2.6
  3. Input: round(1.7+0.9), output: 3
  4. 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:

  1. 7//2 = 3
  2. 7 % 2 = 1(% means mod)
  3. 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值