随笔-113  评论-835  文章-1  trackbacks-0

 

#  说明:21点游戏
#
 语言:python
#
 作者:www.cnweblog.com/luxun
#
 日期:2007-03-08
import  string
import  random
    
def  play():
    again 
=   " y "
    
while  again  ==   " y " :
        your 
=  random.choice([ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])

        pc 
=  random.choice([ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
        
while  pc  <   15 :
            pc 
+=  random.choice([ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])

        s 
=   " y "
        
while  s  ==   " y " :
            
print   " you have  " , your,  "  points. "
            s 
=  raw_input( " if you want more please input y, otherwise input another word.\n " )
            
if  s  ==   " y " :
                your 
+=  random.choice([ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
                
if  your  >   21 :
                    
print   " you are very big!!! your points: " , your

        
print   " PC has  " , pc , " points "
        
if  your  >   21
            
print ( " you lose! " )
        
else :
            
if  pc  >   21
                
print ( " you win!!! " )
            
elif  your  >  pc:
                
print ( " you win!!! " )
            
else :
                
print ( " you lose! " )

        again 
=  raw_input( " if you want to play again please input y, quit input another word.\n " )


if   __name__   ==   " __main__ " :
    play()
posted on 2007-03-08 15:41 老韩 阅读(501) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。
网站导航: