1、三个数(加、减、乘、除、平均值、求最大值)
def arithmetic():
while True:
num_1 = float(input('第一个数:'))
num_2 = float(input('第二个数:'))
num_3 = float(input('第三个数:'))
print('三个数分别为{},{},{}'.format(num_1,num_2,num_3))
play = int(input('进行运算(1.加 2.减 3.乘 4.除 5.平均值 6.MAX >'))
if play == 1:
print('加法运算结果--->%.2f'%(num_1 + num_2 + num_3))
break
elif play == 2:
print('减法运算结果--->%.2f'%(num_1 - num_2 - num_3))
break
elif play == 3:
print('乘法运算结果--->%.2f' % (num_1 * num_2 * num_3))
elif play == 4:
print('除法运算结果--->%.2f'%(num_1 / num_2 / num_3))
elif play == 5:
print('平均值:%.2f'%((num_1+num_2+num_3)/3))
elif play == 6:
print('最大值:',max(num_1,num_2,num_3))
else:
print('识别错误!请重新开始!')
continue
2、类似于求成绩等级的的
def grade():
while True:
performance = float(input('请输入你的分数:'))
if performance <= 100 and performance >= 0:
if performance >= 90:
print('该成绩为{}分,属于优秀!'.format(performance))
elif performance > 60:
print('该成绩为{}分,属于良好!'.format(performance))
else:
print('改成绩{}分,属于及格!'.format(performance))
else:
print('分数异常!重新输入!')
continue
3、BMI指数D
# BMI的计算公式:
# 体质指数(BMI)=体重(kg)÷身高^2(m)
def BMI():
global_variable = '正常'
name = input('姓名:')
age = int(input('年龄:'))
weight = float(input('体重(kg):'))
height = float(input('身高(m):'))
bim_1 = weight / height ** 2
if bim_1 < 18.5:
global_variable = '过轻'
elif 18.5 < bim_1 < 23.9:
pass
elif 24 < bim_1 < 27:
global_variable = '过重!'
elif 28 < bim_1 < 28:
global_variable = '肥胖!!'
else:
global_variable = '非常肥胖!!!'
print('——'*6,'BMI健康体检表','——'*6)
print('姓名:%s 年龄: %d'%(name,age))
print('身高 %.2f 体重 %.0f'%(height,weight))
print('BIM %.f 健康状况:%2s'%(bim_1,global_variable))
4、产生20个[0,5]之间的整数,求每个数字出现的次数
#所以出现的数
import random
Global_list = []
for i in range(20):
random_number = random.randint(0,5)
random_number_list = [random_number]
Global_list.extend(random_number_list)
for i in range(5):
print('数字{}出现了{}次'.format(i,Global_list.count(i)))
print(Global_list)