21 点python

21 点python
#   说明: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()

你可能感兴趣的:(21 点python)