高手求教~~~关于python编程的题目:
发布网友
发布时间:2022-04-24 07:21
我来回答
共2个回答
热心网友
时间:2022-06-17 12:34
看没人理你。。怪可怜的,,,就帮你做好了。。。看代码
#! /usr/bin/env python
#coding=utf-8
'''
Created on 2011-1-29
@author: qihigh
'''
class Ans:
__fruitLeft = 20
__buyDay = 5
__x = None
__y = None
def __init__(self, x, y):
self.__x = x
self.__y = y
def daydayAfter(self,days):
for i in range(1, days+1):
print("self.daySell("+str(i)+")")
# exec("self.daySell("+str(i)+")")
self.daySell(i)
return self.__fruitLeft
def daySell(self,day):
if(self.isSelling(day)):
left = self.__fruitLeft - self.__x
if(left < 0):
self.__fruitLeft = 0
self.__fruitLeft = left
def YArray(self):
self.__fruitLeft = 20
def isSelling(self,day):
''' 卖货周期 5+y'''
if(day%(5+self.__y) == 0):
'''货刚到了 不卖'''
self.YArray();
return False
elif(day%(5+self.__y) <= 5 and self.__fruitLeft != 0):
'''卖'''
return True
else:
'''有货也不卖'''
return False
if __name__ == '__main__':
‘’‘ 传入参数顺序 x 、y ’‘’
ans = Ans(5,1)
print(ans.daydayAfter(32))
热心网友
时间:2022-06-17 12:34
在 Python 3 内,将 raw_input() 重命名为 input()
>>> fourth= input('year:')[3]
year:2005
>>> fourth
'5'
>>>