码迷,mamicode.com
首页 > 编程语言 > 详细

python入门笔记1

时间:2016-06-29 01:01:25      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

一瓶汽水2元,2空瓶可换1汽水,4瓶盖可换1汽水,问10元能喝多少瓶汽水

 1 def duihuan(pingzi,gaizi,qian,jiu):
 2     pingzi = pingzi+(qian/2)
 3     gaizi = gaizi+(qian/2)
 4     jiu = jiu+qian/2
 5     qian = qian%2
 6 
 7     gaizi = gaizi+pingzi/2
 8     jiu = jiu+pingzi/2
 9     pingzi = pingzi%2+pingzi/2
10 
11     pingzi = pingzi+gaizi/4
12     jiu = jiu+gaizi/4
13     gaizi = gaizi%4+gaizi/4
14     print pingzi,"--",gaizi,"--",jiu,"--",qian
15     result = [pingzi,gaizi,qian,jiu]
16     return result
17 
18 aaa = duihuan(0,0,10,0)
19 while(aaa[0]>=2 or aaa[1]>=4 or aaa[2]>=2):
20     aaa = duihuan(aaa[0],aaa[1],aaa[2],aaa[3])

 

结果:

4 -- 4 -- 8 -- 0
3 -- 3 -- 11 -- 0
3 -- 1 -- 13 -- 0
2 -- 2 -- 14 -- 0
1 -- 3 -- 15 -- 0
[Finished in 0.4s]

python入门笔记1

标签:

原文地址:http://www.cnblogs.com/hopor/p/5625459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!