案例8:工作量计算小程序

2020-04-05  本文已影响0人  Iphone60Plus

题目:工作量计算小程序
知识点:自定义函数封装和调用
1-标准大小项目,1个人需要80个小时,也就是10天。
2-交互:用户可选择工时计算或人力计算。
3-用户可选择继续程序或停止程序

# 新知识 math()模块,math.ceil()向上取整
import math

key = 1#程序运行开关

def estimated(my_input):#计算程序
    types =my_input[0]
    size = my_input[1]
    other = my_input[2]
    if (size == None) and (other != None):
        number = math.ceil(types*80/other)
        print('项目大小{},工时{},人员要{}个'.format(types,other,number))
    elif (size != None) and (other == None):
        time = types*80/size
        print('项目大小{},人员{}个,需要工时{}'.format(types,size,time))

def collect():#调入信息,返回元组
    choose = int(input('1代表计算员工人数,2代表计算工时数量,请输入:'))
    if choose == 1:
        types = float(input('请输入项目大小:'))
        other = float(input('请输入需要工时量:'))
        size = None
        return types,size,other
    elif choose == 2:
        types = float(input('请输入项目大小:'))
        size = float(input('请输入员工人数:'))
        other = None
        return types,size,other

def again():#判断是否继续,while循环
    global key
    a = input('是否继续计算?继续请输入y,输入其他键将结束程序。')
    if a != 'y':
        key = 0

def main():
    print('欢迎使用工作量计算小程序')
    while key == 1:
        my_input=collect()
        estimated(my_input)
        again()
    print('感谢使用工作量计算小程序')

main()
上一篇下一篇

猜你喜欢

热点阅读