Battleship!
来源:互联网 发布:netlimiter同类型软件 编辑:程序博客网 时间:2024/05/22 00:21
1.说明:python实现一个打海盗船的程序,对python的if语句list结构进行一个小综合
2.代码
from random import randintboard = []for x in range(5): board.append(["O"] * 5)def print_board(board): for row in board: print " ".join(row)print_board(board)def random_row(board): return randint(0, len(board) - 1)def random_col(board): return randint(0, len(board[0]) - 1)ship_row = random_row(board)ship_col = random_col(board)print ship_rowprint ship_colfor turn in range(4): # Everything from here on should go in your for loop! # Be sure to indent four spaces! guess_row = int(raw_input("Guess Row: ")) guess_col = int(raw_input("Guess Col: ")) if guess_row == ship_row and guess_col == ship_col: print "Congratulations! You sunk my battleship!" break else: if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4): print "Oops, that's not even in the ocean." elif(board[guess_row][guess_col] == "X"): print "You guessed that one already." else: print "You missed my battleship!" board[guess_row][guess_col] = "X" # Print (turn + 1) here! print turn + 1 print_board(board) if turn == 3: print "Game Over"
阅读全文
0 0
- Battleship
- Battleship
- Battleship
- Battleship!
- Python 入门教程 12 ---- Battleship!
- 湖大训练赛第十场 Battleship
- Python学习笔记(5),Battleship 游戏
- [补集转化 有序化去重] Ural 1212 Battleship
- 第十天早课12.13
- ionic 安卓机获取不到$ionicScrollDelegate.getScrollPosition().top的负值
- maven项目使用配置 SSh整合
- Google Guava学习计划第三章Guava Utilities—I/O操作
- 浅谈IT风投
- Battleship!
- APK瘦身套路-项目优化篇
- 一款全兼容的播放器 videojs
- mysql悲观锁总结和实践
- 个人总结70
- 每天一个linux命令(16):which命令
- java的并发简单小结
- Android蓝牙4.0BLE通讯读写数据更新
- 新人报道