Python初级 2 记住内存和变量的练习
一、数据类型:
数字:3, 5, 100, 50.35
字符串:“abc”,“wang”
字符串或数字可以由名字来表示,名字也叫变量
二、算术表达式:
形如3 + 5, 3 * 5
1 数字和符号的组合,Python可以算出它的值
(3 + 5)* 7
(42 - 19)* 3
2 由变量和符号组成,Python可以算出它的值也是算术表达式
a = 3 b = 4 c = 5 a + b (a + b) * c
三、 输入:
input("请输入你的姓名:")
练习:
1 数字:
print(3) print(100) print(2.57) print(300.56)
2 字符串
print("teacher") print("student") print("wang lao shi") print("li lao shi") print("zhang lao shi") print("请输入数字") print("请输入你的姓名")
3 变量
num = 3 print(num) num = 3.15 print(num) num = 100 print(num) teacher = "wang lao shi" print(teacher) teacher = "li lao shi" print(teacher)
4 算术表达式一
print(3+5) print(3*5) print((3+5)*4) print((11-9)*9) print((15-8)*(2+5)) print((25-9)*3-(13-5)) print((5+3)*4-(15-9)*2) print((3+2)*4+9*5+9)
5 算术表达式二
a = 2 b = 3 c = 4 d = 6 sum = a + b print(sum) sum = c + d print(sum) sum = a + b + c + d print(sum) sub = b - a print(sub) sub = d - c print(sub) mul = a * b print(mul) mul = c * d print(mul) mix = (a + b) * c print(mix) mix = (a + b) * (c + d) print(mix)
6 输入