综合 random,[],raw_input,s.strip,s.isspace, format %s %d

 综合例子 random,[] 
1
# -*- coding: UTF-8 -*- 2 import random; 3 4 5 list=["石头","剪刀","","ok"] 6 7 guize=[["石头","剪刀"],["剪刀",""],["","石头"]] 8 9 while True: 10 skey=random.choice(list); #random.randint(1, 108) 11 print "-----电脑出了: ",skey 12 key=raw_input("请输入 石头,剪刀,布 \n") 13 key=key.strip(); 14 if not key or key.isspace(): 15 continue; 16 if key=="ok": 17 print "退出了" 18 break; 19 if not key in list: 20 continue; 21 print "----您出的是 ",key 22 if [key,skey] in guize: 23 print "*******恭喜您胜利*******\n" 24 continue; 25 else: 26 print "^^^^^您输了,再来一局^^^^\n" 27 continue; 28

 

1 principal = 5000        # Initial amount (本金)
2 rate = 0.0655             # Interest rate (利率)
3 numyears = 8            # Number of years (期数,年)
4 year = 1
5 while year <= numyears:
6         principal = principal*(1+rate)
7         print "",year, principal
8         print "%4d %0.3f" % (year, principal)
9         year += 1

 

posted @ 2013-12-11 14:28  zhangxiaodel  阅读(322)  评论(0编辑  收藏  举报