Python小游戏

#!/usr/bin/env pyrhon
#-*- coding: utf-8 -*-
import sys
import time
from random import randint

# ########石头剪子布
while 1:
    s = int(randint(1, 3))
    if s == 1:
        ind = "石头"
    elif s == 2:
        ind = "剪子"
    elif s == 3:
        ind = "布"
    m = raw_input('输入 石头、剪子、布,输入"end"结束游戏:')
    blist = ['石头', "剪子", "布"]
    if (m not in blist) and (m != 'end'):
        print "输入错误,请重新输入!"
    elif (m not in blist) and (m == 'end'):
        print "\n游戏退出中..."
        break
    elif m == ind :
        print "电脑出了: " + ind + ",平局!"
    elif (m == '石头' and ind =='剪子') or (m == '剪子' and ind =='布') or (m == '布' and ind =='石头'):
        print "电脑出了: " + ind +",你赢了!"
    elif (m == '石头' and ind =='布') or (m == '剪子' and ind =='石头') or (m == '布' and ind =='剪子'):
        print "电脑出了: " + ind +",你输了!"

# #########汉诺塔
def pan(n,x,y,z): # x,y,z分别是盘子上的棍子
	if n == 1:
		print (x,'->',z)
	else:
		pan(n-1,x,z,y)    # 将前n-1个盘子从x移动到y
		print (x,'->',z)  # 将最底下盘子从x移动到z
		pan(n-1,y,x,z)    # 将y上n-1个盘子移动到z上
		
n=int(raw_input('请输入汉诺塔的层数:'))
pan(n,'x','y','z')

# ##########摇塞子
result = []
while True:
    result.append(int(randint(1,7)))
    result.append(int(randint(1,7)))
    result.append(int(randint(1,7)))
    print result
    count = 0
    index = 2
    pointStr = ""
    while index >= 0:
        currPoint = result[index]
        count += currPoint
        index -= 1
        pointStr += " "
        pointStr += str(currPoint)
    if count <= 11:
        sys.stdout.write(pointStr + " -> " + "小" + "\n")
        time.sleep( 1 )   # 睡眠一秒
    else:
        sys.stdout.write(pointStr + " -> " + "大" + "\n")
        time.sleep( 1 )   # 睡眠一秒
    result = []
    break

# 猜随机数
num = randint(1,10)
bingo = False
while bingo == False:
	answer = int(raw_input('please input count: '))
	if answer < num:
		print '%s too small' % answer
	elif answer > num:
		print '%s too big' % answer
	elif answer == num:
		print 'BINGO,%s is the right answer!' % answer
		bingo = True
	else:
		pass

你可能感兴趣的:(Python基础)