import sys

 def print_board():
for i in range(3):
for j in range(3):
print map[2 - i][j],
if j != 2:
print '|',
print '' def check_done():
for i in range(3):
if map[i][0] == map[i][1] == map[i][2] != ' ' or map[0][i] == map[1][i] == map[2][i] != ' ':
print turn, "Won!!!"
return True if map[0][0] == map[1][1] == map[2][2] != ' ' or map[0][2] == map[1][1] == map[2][0] != ' ':
print turn, "Won!!!"
return True if ' ' not in map[0] and ' ' not in map[1] and ' ' not in map[2]:
print "Draw"
return True return False turn = 'X'
done = False
map = [[' ', ' ', ' '],
[' ', ' ', ' '],
[' ', ' ', ' ']]
print "Please select position by typing in a number between 1 and 9, see below for which number that is which position..."
print "7|8|9"
print "4|5|6"
print "1|2|3"
print_board()
while done != True:
print turn + "'s turn"
try:
pos = input("Select: ")
if 1 <= pos <= 9:
X = (pos - 1) / 3
Y = (pos - 1) % 3
if map[X][Y] == ' ':
map[X][Y] = turn
print_board()
done = check_done()
if done == False:
if turn == 'X':
turn = 'O'
else:
turn = 'X'
except:
print "You need to add a numeric value"

Python井字游戏的更多相关文章

  1. 初学python第二天

    今天我将用python来编写一款小游戏,用这个来总结一下自己学过的一些基础语法.没错,它就是井字游戏.想想自己第一接触这种游戏,还是小学生呢

  2. (转)Python实例手册

    原文地址:http://hi.baidu.com/quanzhou722/item/cf4471f8e23d3149932af2a7 实在是太好的资料了,不得不转 python实例手册 #encodi ...

  3. 12岁的少年教你用Python做小游戏

    首页 资讯 文章 频道 资源 小组 相亲 登录 注册       首页 最新文章 经典回顾 开发 设计 IT技术 职场 业界 极客 创业 访谈 在国外 - 导航条 - 首页 最新文章 经典回顾 开发 ...

  4. Python编程快速上手——让繁琐工作自动化学习笔记

    第一部分 基本语法 1.字符串不能直接和数字相加,要用str()转一下:但是可以和数字相乘,用于表示多个字符串复制:字符串不能和浮点数直接结合,字符串可以和字符串直接相加: 2.输入函数用input( ...

  5. 转载 python实例手册

    python实例手册 #encoding:utf8# 设定编码-支持中文 0说明 手册制作: 雪松 更新日期: 2013-12-19 欢迎系统运维加入Q群: 198173206 # 加群请回答问题 请 ...

  6. 陈斌python语言基础与应用00

    软件改变生活:购物.餐饮.商旅出行.资料查找... Everybody in this country should learn how to program a computer...because ...

  7. 【转载】python实例手册

    今天写爬虫的时候遇到了问题,在网上不停地查找资料,居然碰到两篇好文章: 1.python实例手册   作者:没头脑的土豆 另一篇在这:shell实例手册 python实例手册 #encoding:ut ...

  8. Python实例手册

    在电脑中突然发现一个这么好的资料,雪松大神制作,不敢独享,特与大家共享.连他的广告也一并复制了吧! python实例手册 #encoding:utf8 # 设定编码-支持中文 0说明 手册制作: 雪松 ...

  9. Python列表推导

    一. 列表推导式   ord() 函数是 chr() 函数(对于8位的ASCII字符串)或 unichr() 函数(对于Unicode对象)的配对函数, 它以一个字符(长度为1的字符串)作为参数,返回 ...

随机推荐

  1. HDU 1978 How many ways DP问题

    How many ways Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. linux学习笔记22---命令diff和diff3

    diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方.diff在命令行中打印每一个行的改动.最新版本的diff还支持二进制文件.diff程序的 ...

  3. [待解决]ColumnPrefixFilter 不能过滤出全部满足条件的,

    Scan scan = new Scan(); ColumnPrefixFilter columnPrefixFilter = new hbase(main)::> scan 't4' ROW ...

  4. Oracle Tuning 总括

    oracle tuning 分为3个阶段 1. application 调优阶段, 包括设计的调优, SQL语句调优, 管理权限等内容, (这部分是我的重点) (调优人员 application de ...

  5. sql server 2008安装要求

    sql server 2008安装要求 新部署的R2需要被安装在格式化为NTFS格式的磁盘上: 微软的.NET Framework 3.5 SP1 微软Windows Installer 4.5或以上 ...

  6. 数据库I/O:CMP、Hibernate

    ★什么是“Persistence” 用过VMWare的朋友大概都知道当一个guest OS正在运行的时候点击“Suspend”将虚拟OS挂起,它会把整个虚拟内存的内容保存到磁盘上,譬如你为虚拟OS分配 ...

  7. ImportError: cannot import name gof

    今天打开spyder说调试一个theano程序,但是import theano提示 ImportError: cannot import name gof 最后解决方案 pip install --u ...

  8. 富文本编辑期Quill

    官方网站http://quilljs.com/ 使用方法 <!-- Create the toolbar container --> <div id="toolbar&qu ...

  9. Machine Learning Yearning - Andrew NG

    链接(1~12章): https://gallery.mailchimp.com/dc3a7ef4d750c0abfc19202a3/files/Machine_Learning_Yearning_V ...

  10. IOS-添加分段控件SegmentControl

    本文转载至 http://www.cnblogs.com/tx8899/archive/2012/06/05/2537020.html 添加分段控件 控件是一种小型的.自包含的UI组件,可以用在各种U ...