|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
class bus_sites:
def __init__(self,sites=53):
self.sites = list(range(1,sites+1))
def check_sites(self):
if self.sites[0] % 2 == 0 and self.sites[0]+1 == self.sites[1]:
return True
else:
return False
def single_buy(self):
self.sites.pop(0)
def show_buy(self):
cs=self.check_sites()
if cs == True:
self.sites.pop(0)
self.sites.pop(0)
else:
self.sites.pop(1)
self.sites.pop(1)
def buy_times(self,number):
count=len(self.sites)
print('剩余的票数是:%d'%count)
print('要购买的票数是%d'%number)
if count>=number:
while number >= 1:
if number==1 or count==2:
self.single_buy()
number-=1
else:
self.show_buy()
number-=2
else:
print('座位不够了')
if __name__ == '__main__':
ss=bus_sites()
i=1
while ss.sites != None:
buy_number=int(input('请输入要购买的票数: '))
print('第%d次购买'%i,'购买的张数是%d'%buy_number)
ss.buy_times(buy_number)
i+=1
print(len(ss.sites),ss.sites) |
|