SHARE
TWEET

Untitled

a guest Sep 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class SweetPotato():
  2.         def  __init__(self):
  3.             #被烤的时间
  4.             self.cook_time = 0
  5.             #地瓜的状态
  6.             self.cook_static = '生的'
  7.             #调料列表
  8.             self.condiments = []
  9.  
  10.         def cook(self,time):
  11.             #烤地瓜的方法
  12.             self.cook_time += time
  13.             if 0 <= self.cook_time < 3:
  14.                 self.cook_static = '生的'
  15.             elif 3 <= self.cook_time <5:
  16.                 self.cook_static = '半生不熟'
  17.             elif 5 <= self.cook_time <8:
  18.                 self.cook_static = '熟的'
  19.             elif self.cook_time >= 8:
  20.                 self.cook_static = '糊的'
  21.  
  22.         def add_condiments(self,condiment):
  23.             #添加调料
  24.             self.condiments.append(condiment)
  25.  
  26.  
  27.         def __str__(self):
  28.             return f'这个地瓜烤了{self.cook_time}分钟,状态时是{self.cook_static},添加的调料有{self.condiments}'
  29.  
  30. digua1 = SweetPotato()
  31.  
  32. print(digua1)
  33.  
  34. digua1.cook(2)
  35. digua1.add_condiments('辣椒')
  36. print(digua1)
  37.  
  38. digua1.cook(6)
  39. digua1.add_condiments('醋')
  40. print(digua1)
  41.  
  42. digua1.cook(2)
  43. print(digua1)
  44.  
  45. digua1.cook(6)
  46. print(digua1)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top