The two most basic python programs
1. Temperature conversion program
#TempConvert.py TempStr = input("Please enter a temperature value with a sign: ") if TempStr[-1] in ['F','f']: C = (eval (TempStr [0: -1]) - 32) /1.8 print("The converted temperature is {:.2f}C".format(C)) elif TempStr[-1] in ['C','c']: F = 1.8 * eval (TempStr [0: -1]) + 32 print("The converted temperature is: {:.2f}F".format(F)) else: print("Incorrect input format")
Computers are developed exponentially with reference to Moore's Law (integration doubles every two years, proposed by Intel Moore in 1965) (the only field in the world that has grown exponentially for more than 50 years, and Moore's Law will continue to grow in the foreseeable 30 years). remain in effect)
The c language was born in 1972 as the first widely used language
Python was born in 1990 and is one of the most popular and best used programming languages today (interpreted languages)
birth time | language type | type of data | founder | |
c | 1972 | static language | Integers, floats, pointers, enums, etc. | DMRitchie (based on B language) |
python | 1990 | scripting language | Integer, Float, String, List | Duido van Rossum |
example | ||
static language | The compiler generates object code at a time, which is more fully optimized and runs faster | c,c++ |
scripting language | Program execution requires source code, maintenance is more flexible, and can cross operating systems | python,php,javascript |
development path | 2002 | 2008 |
python | python2.x | python3.x |
Python is widely used, has powerful third-party libraries, advanced computing ecology, and is a super language. Computing ecology = standard library + third-party library
The evolution of computer technology
1946-1981 计算机系统结构 第一台电脑
1981-2008 网络和视窗 Windows pc时代
2008-2016 08年Android系统出现 进入复杂信息系统时代
16-今 人工智能时代 16年alphago
import用法
1 import turtle 后面调用时 比如这样turtle.penup()
2 from turtle import* 后面调用时,不用加turtle, 直接加函数名,但缺点也很明显。3 import turtle as bieming 可以起个小名,可以简化编程,例如import turtle as t
循环语句 range() for 变量 in range()
for 变量 range (i): #意思是变量从0到i-1次
range() 产生循环计数数列
range(n) 产生0 到 n-1
range(m,n) 产生m到 n-1的整数序列