先做个介绍
1、vim my_introduce2.py
编辑内容:
#! /usr/bin/env python
name = "frinds of the wind"
age = 29
gender = True
height = 1.82
weight=79
print(name)
print(age)
print(gender)
print(height)
print(weight)
赋予执行权:注意,必须赋权才行
(py3) [root@ansible lesson9]

2、扩展:29前面加个age:很清楚知道是年龄,而不是您的存款!看起来更方便,用到字符串拼接。 分析:29是整数类型,不能直接拼接,需要将其转换成字符串,整数不用加“”,加上表示是字符串类型。 vim my_introduce.py
添加内容并保存
n = "name:"
name = "friends of the wind"
a = "age:"
age = str("29")
g = "gender:"
gender = str("True")
h = "height:"
height = str("1.82")
w = "weight:"
weight = str("79")
print(n + name)
print(a + age)
print(g + gender)
print(h + height)
print(w + weight)
验证: 
颜值测试
计算您的颜值是否达标
price = float(input("颜值分数:"))
weight = float(input("人品:"))
money = price * weight
s = "帅爆啦!"
print(s,money)
验证: 
目标:告诉她,I love you !
提示:终于脱单了(加个前提,是将要,关键她答不答应) 心理蹦蹦跳,她是接受我呢?还是接受我呢?要事说两遍。
(py3) [root@ansible lesson9]
(py3) [root@ansible lesson9]
(py3) [root@ansible lesson9]
编辑内容:  执行结果:  分析:这里用到了注释、函数print 单行 # 多行 " " "或’’’ print打印内容到屏幕
购物计价
格式化输出表:
字符 | 含义 |
---|
%s | 字符串 | %d | 十进制整数,%06d表示输出的整数位数,不足位数地方以0补齐 | %f | 浮点数,%.02f表示小数点后显示两位 | %% | 输出% |
以买水果脚本为例。
编辑:vim shopping.py 添加内容:
price = float(input("单价:"))
weight = float(input("重量:"))
money = price * weight
print("单价 %.02f 元/斤,共 %.02f 斤,支付 %.02f 元" % (price,weight,money))
验证: 
|