Mybatis_Aniu
业精于勤而荒于嬉!

导航

 

1.猜数字小游戏

#!/usr/bin/python
#-*-coding:utf-8-*-

import random
print "-------------------------------------"
print "欢迎使用aniuzaixian编写的猜数字小游戏"
print "+++++请阅读游戏规则+++++"
s = int(random.uniform(1,100))
print """游戏规则:1.请输入1-100(不包括100)之间的任意整数,/
         2.输入0,退去游戏!"""
print "------------------------------------"

name= raw_input("请输入你的姓名:")
print "欢迎%s接受挑战!"%name
m=-1
while s != m:

        str=raw_input("请输入整数:")
        if(str.isdigit()):
                m=int(str)
                if m > s:
                        print "猜大了"
                        continue
                elif m == 0:
                        print "欢迎下次再试"
                        break
                elif m < s:
                        print "猜小了"
                        continue
        else:
                print "请输入1-100之间的数字,不包含其他字符串"
                continue
else:
        print "%s太棒了,猜对了"%name

 

2.猜拳小游戏

#!/usr/bin/env python
#-*-coding:utf-8 -*-
import random

print "欢迎使用aniuzaixian猜拳游戏软件!"
print """请阅读游戏规则:
         1.请输入"石头","剪刀","布"中的任意一个
         2.输入 end,结束游戏!
"""
name=raw_input("请输入你的名字:")
print "欢迎%s猜拳"%name

com=0
per=0
draw=0
while True:
        s=int(random.randint(1,3))
        computer="电脑出拳"
        if(s==1):
                computer="剪刀"
        elif(s==2):
                computer="石头"
        else:
                computer=""
        person=raw_input("请出拳:")
        list=["石头","剪刀",""]
        if(person in list) and (person != "end"):
                if(computer == person):
                        print "平手了"
                        draw+=1
                        continue
                elif(computer=="石头" and person=="剪刀") or (computer=="剪刀" and person=="") or (computer=="" and person=="石头"):
                        print "电脑赢了"
                        com+=1
                else:
                        print "%s赢了"%name
                        per+=1
        elif(person not in list) and (person != "end"):
                print "你输入有误,请重新输入!"
                continue
        else:
                sum = com + per + draw
                print "这次游戏,%s共猜拳%d次,赢拳%d次,输拳%d次,平手%d次" %(name,sum,per,com,draw)
                print "欢迎%s下次再玩!"%name
                break

 

posted on 2017-10-24 22:26  Mybatis_Aniu  阅读(677)  评论(3编辑  收藏  举报