进入宝藏洞

import time
import randomdef displayFintro():print('''You are in a land full of dragons. In front of you,you see two caves. In one cave, the dragon is friendlyand will share his treasure with you. The other dragonis greedy and hungry, and will eat you on sight.''')
print()def chooseCave():cave=''while cave !='1' and cave !='2':print('Which cave will you go into?( 1 or 2)')cave=input()return cave
def checkCave(chooseCave):print('You approach the cave.....')time.sleep(2)print('It is dark and spooky....')time.sleep(2)print('A large dragon jumps ou in front of you! He opens his jaws and ....')print()time.sleep(2)friendlyCave=random.randint(1,2)if chooseCave == str(friendlyCave):print('Give you his treasure!')else:print('Gobbles you down in one bite!')
playAgain='yes'
while playAgain=='yes' or playAgain=='Y':displayFintro()caveNumber =chooseCave()checkCave(caveNumber)print('Do you want to play again?(yes or no)')playAgain= input()

上吊人游戏代码

import randomHANGMAN_PICS = ['''+---+|||===''', '''+---+O   |||===''', '''+---+O   ||   ||===''', '''+---+O   |/|   ||===''', '''+---+O   |/|\  ||===''', '''+---+O   |/|\  |/    |===''', '''+---+O   |/|\  |/ \  |===''']
words = 'cat words'.split(' ')def getRandomWord(wordList):wordIndex = random.randint(0, len(wordList) - 1)return wordList[wordIndex]def displayBoard(missedLetters, correctLetters, secretword):print(HANGMAN_PICS[len(missedLetters)])print()print('Missed letters:', end=' ')for letter in missedLetters:print(letter, end=' ')print()blanks = '*' * len(secretword)for i in range(len(secretword)):if secretword[i] in correctLetters:blanks = blanks[:i] + secretword[i] + blanks[i + 1:]for letter in blanks:print(letter, end=' ')print()def getGuess(alreadyGuessed):while True:print('Guess a letter:')guess = input()guess=guess.lower()if len(guess) != 1:print('Please enter a single letter.')elif guess in alreadyGuessed:print('You have already guessed that letter. Choose again.')elif guess not in 'abcdefghijklmnopqrstuvwxyz':print('Please enter a LETTER.')else:return guessdef playAgain():print('Do you want to play again?( yes or no)')return input().lower().startswith('y')print('H A N G M A N')
missedLetters = ''
correctLetters = ''
secretWord = getRandomWord(words)
gameIsDone = Falsewhile True:displayBoard(missedLetters, correctLetters, secretWord)guess = getGuess((missedLetters + correctLetters))if guess in secretWord:correctLetters = correctLetters + guessfoundAllLetters = Truefor i in range(len(secretWord)):if secretWord[i] not in correctLetters:foundAllLetters = Falsebreakif foundAllLetters:print('Yes! The secret word is ' + secretWord + '! you have won!')gameIsDone = Trueelse:missedLetters = missedLetters + guessif len(missedLetters) == len(HANGMAN_PICS) - 1:displayBoard(missedLetters, correctLetters, secretWord)print('You have run out of guesses!\nAfter ' + str(len(missedLetters)) + ' missed guesses and ' + str(len(correctLetters)) + ' correct guesses,the word was "' + secretWord + '"')gameIsDone = Trueif gameIsDone:if playAgain():missedLetters = ''correctLetters = ''gameIsDone = FalsesecretWord = getRandomWord(words)else:break

python 简单文字游戏代码相关推荐

  1. python写剧情文字游戏_python 简单文字游戏代码

    进入宝藏洞 import time import random def displayFintro(): print('''You are in a land full of dragons. In ...

  2. python简单入门代码-Python入门 | IDLE的介绍和使用方法

    本篇目录: 什么是IDLE 通过一个简单示例来学习IDLE的使用 写在最后 一.什么是IDLE: IDLE是在Python安装时自动安装的一个集成开发环境(IDE),事实上,这也是我目前见过的最最轻量 ...

  3. python简单程序代码-有那些用python修改python程序代码的简单方法?

    python源代码是用C写的. 想改源库用python实现好像不太现实. 按你的要求,用C来extend的话很简单. ============下面是扩展库的代码=========== 用C来exten ...

  4. python简单程序代码-简单python代码

    菜鸟独白 Python语言非常优美,语法简洁而功能强大,容易上手,学好Python能干很多事情:比如爬虫,数据分析呀,机器学习啊,web开发,其实Python还能帮你赚钱,比如自己做一个量化分析的小工 ...

  5. python简单爬虫代码-python爬虫超简单攻略,带你写入门级的爬虫,抓取上万条信息...

    原标题:python爬虫超简单攻略,带你写入门级的爬虫,抓取上万条信息 最近经常有人问我,明明看着教程写个爬虫很简单,但是自己上手的时候就麻爪了...那么今天就给刚开始学习爬虫的同学,分享一下怎么一步 ...

  6. python简单爬虫代码-最精简的爬虫 --仅需4行代码(python)

    最精简的爬虫 --仅需4行代码(python) 刚刚整理了下爬虫系列,于是乎就开始了第一次的技术分享 今天,我们主要讲述的是思路,思路,思路. 相比起,直接贴代码,思路显的更为重要 当初,自己的坑,希 ...

  7. python简单爬虫代码-一则python3的简单爬虫代码

    不得不说python的上手非常简单.在网上找了一下,大都是python2的帖子,于是随手写了个python3的.代码非常简单就不解释了,直接贴代码. 代码如下: #test rdp import ur ...

  8. python简单编程代码表白,Python简单编程游戏代码

    什么是python编程 Python是一门新兴的编程语言,编程语言有很多,比如C++.Java.C#.PHP.JavaScript等,Python也是其中之一,在学习Python前,我们需要对它有一定 ...

  9. python读取游戏数据_一个python简单文字游戏里的数据征集

    ‍好吧,最近突然想用python做一个十分简单的小游戏,不过我现在要收集一些精灵数据啥的,各位可以帮个忙吗?(=・ω・=) 投稿邮箱:3072851485@qq.com 投稿格式: 两个文本文档(.t ...

  10. 4、python简单线性回归代码案例(完整)_4、python简单线性回归代码案例(完整)...

    第一.回归分析的步骤 01 根据预测目标,确定自变量和因变量 02 绘制散点图,确定回归模型类型 03 估计模型参数,建立回归模型 04 对回归模型进行检验 回归方程的精度就是用来表示实际观测点和回归 ...

最新文章

  1. 符合自己的德国学校与专业
  2. 古怪的ConfigurationManager
  3. pandas的dataframe
  4. 关于Socket踩过的一些坑
  5. vs2017添加引用出错:对COM组件的调用返回了错误HRESULT E_FAIL
  6. 原根算法C语言,数据结构与算法分析 C语言描述(第2版)Larry Nyhoff AVL树
  7. .net GridView绑定数据、编辑、更新、删除(弹出确认对话框)、取消、根据条件隐藏或显示按钮操作
  8. Centos开机自动执行shell脚本启动tomcat服务器
  9. 数模美赛-层次分析模型方法(评价类问题)
  10. android studio : Could not find org.jetbrains.kotlin:kotlin-stdlib-jre7:1.5.31
  11. 倍福---绝对值编码器位置保存
  12. O2O营销模式的特点
  13. 第五十三篇 三角函数公式大全
  14. [转载]美国签证敏感专业列表Technology Alert List_拔剑-浆糊的传说_新浪博客
  15. fast-lio2论文阅读 《FAST-LIO2: Fast Direct LiDAR-inertial Odometry》
  16. 颜体html标签,颜体楷书笔法32式详解,一定不能错过!(超级干货)
  17. 不需要密码卸载Symantec Endpoint Protection
  18. 安全漏洞中的倚天剑——XSS跨站脚本攻击
  19. 仿 IOS 打造一个全局通用的对话框
  20. 【git系列004】解决 git 未指定冲突处理方法的问题

热门文章

  1. Meteor在手机上运行
  2. ssh远程连接网络构建
  3. Google不要成为在垃圾桶里翻扒的猫
  4. hive安装及常用命令
  5. python爬虫网络出错怎么办_python网络爬虫(3)python爬虫遇到的各种问题(python版本、进程等)...
  6. vmware-tools for LFS
  7. 添加本地cdrom到RHEL yum 源
  8. html5 h264 websocket,2.5 在WebSocket中使用HTML5媒体
  9. 怎么获取php内的参数,php如何获取方法内的所有参数
  10. 3D图形原理和一些基本概念