MENU

AA付款:自学Python后写的第一个实用程序(更新为V2.0)

February 19, 2019 • 学习阅读设置

很臃肿的代码,而且命名都是中文,小白学习之路,大胆的放上来,后续继续优化

需求: 假如上周总共餐费:312 rmb
用餐人数:12 总共用餐:3餐
其中: 吃3餐的人数:10 吃2餐的人数:2
每餐= 312/12/3 = 8.66
吃2餐的平摊金额是 8.66*2=17.32
吃3餐的平摊金额是:(312-17.32*2)/10= 277.36/10 = 27.36

AA付款 V2.0
by wxd
time:2019.02.25

average_cost =0
class Equal_cost():
     @classmethod
     def input(cls):
        cls.sum = float(input('请输入上周平摊总金额:'))
        cls.number_people = float(input('请输入上周参与吃饭人数:'))
        cls.number_meals = float(input('请输入上周总共餐数:'))
        cls.eat_one = float(input('请输入吃一餐人数:'))
        cls.eat_tow = float(input('请输入吃二餐人数:'))
        cls.eat_three = float(input('请输入吃三餐人数:'))
        cls.eat_four = float(input('请输入吃四餐人数:'))
        cls.eat_five = float(input('请输入吃五餐人数:'))
     @classmethod
     def money(cls):
       cls.average_cost = cls.sum/(cls.eat_one*1+cls.eat_tow*2+cls.eat_three*3+cls.eat_four*4+cls.eat_five*5) #平均每人每餐金额
       cls.eat_one_money = cls.average_cost*1 #只吃一餐的人需要缴纳的金额
       cls.eat_tow_money = cls.average_cost*2
       cls.eat_three_money = cls.average_cost*3
       cls.eat_four_money = cls.average_cost*4
       cls.eat_five_money = cls.average_cost*5
       print('上周平摊总金额:'+str(cls.sum))
       print('上周吃饭人数:'+str(cls.number_people))
       print('上周总共餐数:'+str(cls.number_meals))
       print('平均每人每餐:'+str(cls.average_cost))
       print('吃一餐的同学要交:'+str(cls.eat_one_money))
       print('吃二餐的同学要交:'+str(cls.eat_tow_money))
       print('吃三餐的同学要交:'+str(cls.eat_three_money))
       print('吃四餐的同学要交:'+str(cls.eat_four_money))
       print('吃五餐的同学要交:'+str(cls.eat_five_money))     
Equal_cost.input()
Equal_cost.money()

AA付款 V1.0
by wxd
time:2019.02.18

class AA付款():
 @classmethod
 def 参数录入(cls):
    cls.平摊总金额 = float(input('请输入上周平摊总金额:'))
    cls.总人数 = float(input('请输入上周参与吃饭人数:'))
    cls.餐数 = float(input('请输入上周总共餐数:'))
    cls.少吃一餐人数 = float(input('请输入少吃一餐人数:'))
    cls.少吃二餐人数 = float(input('请输入少吃二餐人数:'))
    cls.少吃三餐人数 = float(input('请输入少吃三餐人数:'))
    cls.少吃四餐人数 = float(input('请输入少吃四餐人数:'))
 @classmethod
 def 计算平摊金额(cls):
    if cls.少吃一餐人数 == 0 and cls.少吃二餐人数==0 and  cls.少吃三餐人数==0 and cls.少吃四餐人数==0 :
       平均分摊金额 = float(cls.平摊总金额/cls.总人数)
       print('==========我是分割线==========')
       print('上周平摊总金额:'+str(cls.平摊总金额))
       print('上周吃饭人数:'+str(cls.总人数))
       print('上周每人均摊:'+str(平均分摊金额))
    elif cls.少吃一餐人数 > 0 :
       平均每餐金额 = float(cls.平摊总金额/cls.总人数/cls.餐数)
       少吃一餐平摊金额=float(平均每餐金额*(cls.餐数-1))
       其他平摊金额=float((cls.平摊总金额-(平均每餐金额*cls.少吃一餐人数*(cls.餐数-1)))/10)
       print('==========我是分割线==========')
       print('上周平摊总金额:'+str(cls.平摊总金额))
       print('上周吃饭人数:'+str(cls.总人数))
       print('上周总共餐数:'+str(cls.餐数))
       print('上周少吃一餐的同学要交:'+str(少吃一餐平摊金额))
       print('其他的同学要交:'+str(其他平摊金额))
    elif cls.少吃二餐人数 > 0 :
       平均每餐金额 = float(cls.平摊总金额/cls.总人数/cls.餐数)
       少吃二餐平摊金额=float(平均每餐金额*(cls.餐数-2))
       其他平摊金额=float((cls.平摊总金额-(平均每餐金额*cls.少吃二餐人数*(cls.餐数-2)))/10)
       print('==========我是分割线==========')
       print('上周平摊总金额:'+str(cls.平摊总金额))
       print('上周吃饭人数:'+str(cls.总人数))
       print('上周总共餐数:'+str(cls.餐数))
       print('上周少吃二餐的同学要交:'+str(少吃二餐平摊金额))
       print('其他的同学要交:'+str(其他平摊金额))
    elif cls.少吃三餐人数 > 0 :
       平均每餐金额 = float(cls.平摊总金额/cls.总人数/cls.餐数)
       少吃三餐平摊金额=float(平均每餐金额*(cls.餐数-3))
       其他平摊金额=float((cls.平摊总金额-(平均每餐金额*cls.少吃三餐人数*(cls.餐数-3)))/10)
       print('==========我是分割线==========')
       print('上周平摊总金额:'+str(cls.平摊总金额))
       print('上周吃饭人数:'+str(cls.总人数))
       print('上周总共餐数:'+str(cls.餐数))
       print('上周少吃三餐的同学要交:'+str(少吃三餐平摊金额))
       print('其他的同学要交:'+str(其他平摊金额))
    elif cls.少吃四餐人数 > 0:
        平均每餐金额 = float(cls.平摊总金额/cls.总人数/cls.餐数)
        少吃四餐平摊金额=float(平均每餐金额*(cls.餐数-4))
        其他平摊金额=float((cls.平摊总金额-(平均每餐金额*cls.少吃四餐人数*(cls.餐数-4)))/10)
        print('==========我是分割线==========')
        print('上周平摊总金额:'+str(cls.平摊总金额))
        print('上周吃饭人数:'+str(cls.总人数))
        print('上周总共餐数:'+str(cls.餐数))
        print('上周少吃四餐的同学要交:'+str(少吃四餐平摊金额))
        print('其他的同学要交:'+str(其他平摊金额))
    else:
       print('请重新输入参数')
AA付款.参数录入()
AA付款.计算平摊金额()
Last Modified: February 28, 2019
Archives QR Code
QR Code for this page
Tipping QR Code