欢迎关注 『Python从入门到实战100天』 系列,持续更新中
欢迎关注 『Python从入门到实战100天』 系列,持续更新中
value = float(input('请输入长度: '))
unit = input('请输入单位: ')
if unit == 'in' or unit == '英寸':
print('%f英寸 = %f厘米' % (value, value * 2.54))
elif unit == 'cm' or unit == '厘米':
print('%f厘米 = %f英寸' % (value, value / 2.54))
else:
print('请输入有效的单位')
score = float(input('请输入成绩: '))
if score >= 90:
grade = 'A'
elif score >= 80:
grade = 'B'
elif score >= 70:
grade = 'C'
elif score >= 60:
grade = 'D'
else:
grade = 'E'
print('对应的等级是:', grade)
# 分段函数求值
# 3x - 5 (x > 1)
# f(x) = x + 2 (-1 <= x <= 1)
# 5x + 3 (x < -1)
x = float(input('x = '))
if x > 1:
y = 3 * x - 5
elif x >= -1:
y = x + 2
else:
y = 5 * x + 3
print('f(%.2f) = %.2f' % (x, y))
randint(1, 6) 表示1-6随机一个整数!注意,这里右侧区间的6可以取得到
from random import randint
face = randint(1, 6)
if face == 1:
result = '看书'
elif face == 2:
result = '跑步'
elif face == 3:
result = '敲代码'
elif face == 4:
result = '打游戏'
elif face == 5:
result = '吃饭'
else:
result = '睡觉'
print("随机数是:{}".format(face))
print(result)
这是老版本过时的计算方式,新版本的计算可能有出入
salary = float(input('本月收入: '))
insurance = float(input('五险一金: '))
diff = salary - insurance - 3500
if diff <= 0:
rate = 0
deduction = 0
elif diff < 1500:
rate = 0.03
deduction = 0
elif diff < 4500:
rate = 0.1
deduction = 105
elif diff < 9000:
rate = 0.2
deduction = 555
elif diff < 35000:
rate = 0.25
deduction = 1005
elif diff < 55000:
rate = 0.3
deduction = 2755
elif diff < 80000:
rate = 0.35
deduction = 5505
else:
rate = 0.45
deduction = 13505
tax = abs(diff * rate - deduction)
print('个人所得税: ¥%.2f元' % tax)
print('实际到手收入: ¥%.2f元' % (diff + 3500 - tax))
判断输入的边长能否构成三角形
如果能则计算出三角形的周长和面积
import math
a = float(input('a = '))
b = float(input('b = '))
c = float(input('c = '))
if a + b > c and a + c > b and b + c > a:
print('周长: %f' % (a + b + c))
p = (a + b + c) / 2
area = math.sqrt(p * (p - a) * (p - b) * (p - c))
print('面积: %f' % (area))
else:
print('不能构成三角形')
username = input('请输入用户名: ')
password = input('请输入口令: ')
if username == 'admin' and password == '123456':
print('身份验证成功!')
else:
print('身份验证失败!')
!!!下面的代码不能在pycharm中使用!!!
import getpass
username = input('请输入用户名: ')
password = getpass.getpass('请输入口令: ')
# 输入口令的时候终端中没有回显
# 类似linux系统的密码输入,但是不能在pycharm中使用,可以在别的编译器使用
if username == '发现你走远了' and password == '123456':
print('身份验证成功!')
else:
print('身份验证失败!')
大家喜欢的话,给个,点个关注!给大家分享更多有趣好玩的Python学习笔记!
本专栏系列内容基于开源项目jackfrued-Python-100-Days
欢迎关注 『Python从入门到实战100天』 系列,持续更新中
欢迎关注 『Python从入门到实战100天』 系列,持续更新中
【更多内容敬请期待】