天天学习$
发表于 2018-4-17 20:17:31
本帖最后由 天天学习$ 于 2018-4-17 20:21 编辑
def tickets(people):
i = 0
for temp in people:
if (temp - 25) == 0 or (temp - 25) <= (i * 25) :
pass
else:
return 'no'
break
i += 1
return 'yes'
萧丹夜
发表于 2018-5-26 21:23:09
貌似可行
def Booking(x):
y ={100:0,50:0,25:0}
for each in x:
if each == 100:
y += 1
if y >= 1 and y >= 1:
y -= 1
y -= 1
elif y >= 3:
y -= 3
else:
break
elif each == 50:
y += 1
if y >= 1:
y -= 1
else:
break
elif each == 25:
y += 1
else:
return '输入有误!'
else:
return 'yes'
return 'no'
x = list(map(int,input('请输入排队购票金额:').split()))
result = Booking(x)
print(result)
475123763
发表于 2018-7-16 23:24:51
a =
n25 = 0
n50 = 0
n100 = 0
for i in range(0,6):
if a == 25:
n25 = n25 + 1
if i == 6:
print("yes")
if a == 50:
n50 = n50+1
if n25 > 0:
n25 = n25-1
else:
print("no")
if a == 100:
if n50>0:
n50 = n50 -1
if n25>2:
n25 = n25 -3
else:
print('no')
自己这个程序有问题,感觉自己写的好累,还是要多加油
小强工作室
发表于 2018-8-1 14:33:38
学习一下
jrro452
发表于 2018-8-23 16:45:52
看看楼主的方法
jrro452
发表于 2018-8-23 16:46:53
def tickets(people):
ticketmoney ={'25':0,'50':0,'100':0}
x=0
for i in range(len(people)):
x+=1
if people != 25:
return 'No'
break
ticketmoney)]+=1
if people==50:
if ticketmoney['25']>=1:
ticketmoney['25']-=1
else:
return 'No'
break
if people==100:
if ticketmoney['50']==0 and ticketmoney['25']>=3:
ticketmoney['25']-=3
elif ticketmoney['25']>1 and ticketmoney['50']>=1 :
ticketmoney['25']-=1
ticketmoney['50']-=1
else:
return 'No'
break
if x==len(people):
return 'Yes'
people =
print(tickets(people))
结果“Yes”
jiaozhu80
发表于 2018-9-2 21:09:12
本帖最后由 jiaozhu80 于 2018-9-3 12:08 编辑
def ticket(people):
price_dict={25:0,50:0}
result=[]
for i in range(len(people)):
if people==25:
result.append("yes")
price_dict+=1
elif people==50:
if price_dict>1 or price_dict==1:
result.append("yes")
price_dict-=1
price_dict+=1
else:
result.append("no")
elif people==100:
if (price_dict*price_dict>=1)or (price_dict==3):
result.append("yes")
if price_dict>=1:
price_dict-=1
price_dict-=1
else:
price_dict-=3
else:
result.append("no")
print(price_dict,price_dict,result)
if "no" not in result:
return "yes"
else:
return "no"
jiaozhu80
发表于 2018-9-2 21:12:53
您好:请问if __name__=="__main__":表示什么意思?
算幽幽
发表于 2018-9-25 22:55:17
I love Fishc
def tickets(people):
count=0
for i in people:
sum=count*25
ifi-sum>25 or(i-sum)%25!=0:
print(i,sum)
return 'no'
count += 1
else:
print(i, sum)
return 'yes'
print(tickets())
算幽幽
发表于 2018-9-25 23:00:15
算幽幽 发表于 2018-9-25 22:55
I love Fishc
还是有问题
lyslyslys
发表于 2018-9-27 13:41:11
感谢
double-lee
发表于 2018-12-11 16:29:54
def tickets(people):
total = {25:0,50:0,100:0}
for i in range(len(people)):
if i == 0 and people != 25:
return 'no'
elif people == 50 and total == 0:
return 'no'
elif people == 25:
total += 1
elif people == 50 and total >= 1:
total -= 1
total += 1
elif people == 100:
if total == 0 and total < 3:
return 'no'
elif total > 0 and total == 0:
return 'no'
elif total == 0 and total >= 3:
total += 1
total -= 3
elif total > 0 and total > 0:
total += 1
total -= 1
total -= 1
else:
return 'yes'
新手小白把可能的情况都列出来了。。。{:5_107:}
3333332
发表于 2019-2-27 10:14:44
谢谢
不忘初心1020
发表于 2019-2-27 10:23:08
无处不编程
yu123py
发表于 2019-4-30 21:53:02
给我鱼币!
def faulty_odometer(i):
c = 0
j = 1
while j <= i:
if '4' in str(j):
jump = 10 ** (len(str(j)) - str(j).index('4') - 1)
c += jump
j += jump
j += 1
return i - c
panheng
发表于 2019-8-23 10:29:26
def tickets(custom):
for each in custom:
change = each - 25
if change == 0: #不用找钱
dict1['25'] += 1
elif change == 75: #找75块
if dict1['50'] > 0 and dict1['25'] > 0:
dict1['50'] -= 1
dict1['25'] -= 1
dict1['100'] += 1
elif dict1['25'] >= 3:
dict1['25'] -= 3
dict1['100'] += 1
else:
return False
else: #找25块
if dict1['25'] >0:
dict1['25'] -= 1
dict1['50'] += 1
else:
return False
else:
return True
if __name__ == '__main__':
dict1 = {'100': 0, '50': 0, '25': 0} #初始资金池
str1 = input('请输入每人放入的金额面值,以“,”分隔')
custom =
result = tickets(custom)
print(result)
if result:
print(dict1)
克里斯保罗
发表于 2019-9-4 17:27:41
import test
def tickets(people):
temp = []
temp.append(25)
length = len(people)
if people!=25:
return 'NO'
for each in range(1,length):
ch= people - 25
if ch == 0:
temp.append(people)
else:
if people == 100:
if 25 in temp and 50 in temp:
temp.remove(25)
temp.remove(50)
temp.append(100)
else:
return 'NO'
elif people == 50:
if 25 not in temp:
return 'NO'
else:
temp.remove(25)
temp.append(50)
return 'YES'
test.assert_equals(tickets(), 'YES')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'YES')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'YES')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'YES')
test.assert_equals(tickets(),'NO')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'NO')
test.assert_equals(tickets(), 'NO')
杜若左
发表于 2020-4-1 17:59:46
gopythoner 发表于 2017-4-25 20:17
我写了一个,把你上面的测试了,全部正确
大佬,牛皮。你的是我看道最简洁易懂的。谢谢
holiday_python
发表于 2020-4-19 18:29:50
d
19971023
发表于 2020-6-5 17:32:35
1