英制单位和公职单位转换
#! /usr/bin/env python
"""
@Time : 2018/8/21 11:14
@Author : Damao
@Site : Life is short. I use python.
@File : test1.py
@Software : PyCharm
"""
num = 1.23213213
# 保留小数点后2位
print("保留小数点后2位数:{a}".format(a=round(num,3)))
print("保留小数点后2位数:%.2f" %num)
"""英制单位和公职单位转换"""
value = float(input("请输入长度:"))
unit = input("请输入单位:")
if unit == '厘米' or unit == 'cm':
print("{a}厘米={b}英尺".format(a=round(value,5),b=round(value / 2.54,5)))
elif unit == 'in' or unit == '英尺':
print("%f英尺=%f厘米" %(value,value * 2.54))
百分制成绩转等级制成绩
#! /usr/bin/env python
"""
@Time : 2018/8/21 13:55
@Author : Damao
@Site : Life is short. I use python.
@File : test2.py
@Software : PyCharm
"""
"""
百分制成绩转等级制成绩
90分以上 --> A
80分~89分 --> B
70分~79分 --> C
60分~69分 --> D
60分以下 --> E
"""
socre = float(input("请输入成绩分数:"))
if socre >= 90:
level = 'A'
elif socre >= 80:
level = 'B'
elif socre >= 70:
level = 'C'
elif socre >= 60:
level = 'D'
else:
level = 'E'
print("对应的等级为:{a}".format(a=level))
条件运算
#! /usr/bin/env python
"""
@Time : 2018/8/21 14:04
@Author : Damao
@Site : Life is short. I use python.
@File : test3.py
@Software : PyCharm
"""
"""条件运算"""
x = float(input('x = '))
if x > 1:
y = 3 * x - 5
elif x >= -1:
y = x + 2
else:
y = 5 * x + 3
print("f({a})={b}".format(a=x,b=y))
筛子游戏
#! /usr/bin/env python
"""
@Time : 2018/8/21 14:08
@Author : Damao
@Site : Life is short. I use python.
@File : test4.py
@Software : PyCharm
"""
from random import randint
"""筛子游戏"""
num = randint(1,6)
if num == 1:
result = '唱首歌'
elif num == 2:
result = '跳个舞'
elif num == 3:
result = '学狗叫'
elif num == 4:
result = '做俯卧撑'
elif num == 5:
result = '念绕口令'
else:
result = '讲冷笑话'
print(result)
确定能不能构成一个三角形及构成三角形后的三角形面积及周长
#! /usr/bin/env python
"""
@Time : 2018/8/21 16:53
@Author : Damao
@Site : Life is short. I use python.
@File : test5.py
@Software : PyCharm
"""
import math
"""确定能不能构成一个三角形及构成三角形后的三角形面积及周长"""
a = int(input("请输入第一个值:"))
b = int(input("请输入第一个值:"))
c = int(input("请输入第一个值:"))
if a+b >c and a+c >b and b+c >a:
print("能够成三角形!")
perimeter = a + b + c
print("周长为:{a}".format(a=round(perimeter,2)))
p = (a + b + c) / 2
area = math.sqrt(p * (p - a) * (p - b) * (p - c))
print('面积为: %f' % (area))
else:
print("不能构成三角形!")
用户名密码验证
#! /usr/bin/env python
"""
@Time : 2018/8/21 17:31
@Author : Damao
@Site : Life is short. I use python.
@File : test6.py
@Software : PyCharm
"""
"""用户名密码验证"""
username = input("请输入用户名:")
password = input("请输入密码:")
if type(username) is str and password =='123456':
print("登录成功!")
else:
print("登录失败!")
网友评论