majian890324 发表于 2020-6-20 14:40:15

Python第37讲,动手第一题,门票问题

本帖最后由 majian890324 于 2020-6-20 14:41 编辑

我看小甲鱼写的代码和在论坛里搜的其他人的代码都需要在shell里实例化对象后再调用方法,那么我这么直接写在py文件里是不是就是不对的?
class Tickites:
    day = 100
    people = 1
    people_new = 1


    def days(self,week):
      if week == '平日':
            self.day = 100
      elif week == '周末':
            self.day = 100 * 1.2

    def peoples(self,old_people,new_pelople):
      self.people = old_people
      self.people_new = new_pelople

    def mon(self):
      pop = self.people * self.day + (self.people_new * self.day)/2
      print('因为今天是%s,所以%d成人和%d儿童的票价为:%.2f' % (week,self.people,self.people_new,pop))




week = input('今天是平日还是周末:')
old_people = float(input('有几个成年人:'))
new_pelople = float(input('有几个儿童:'))


money = Tickites()
money.days(week)
money.peoples(old_people,new_pelople)
money.mon()

Twilight6 发表于 2020-6-20 14:51:04



都可以滴,怎么会不对呢? 直接写 py 里面实例化没毛病~
页: [1]
查看完整版本: Python第37讲,动手第一题,门票问题