进入宝藏洞

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. 备份与恢复oracle,oracle 备份与恢复
  2. Nginx——反向代理
  3. PL/SQL-FOR UPDATE 与 FOR UPDATE OF的区别
  4. 阿特斯携手EDF启动建设巴西191.5MW光伏项目
  5. 从数据库层面手动删除zabbix告警
  6. Unity时钟定时器插件
  7. android file transfer下载_PHP通过header方式下载文件
  8. javascript arguments对象研究--针对jquery源码研究再研究
  9. mac 设置php时区,mac环境下PHP系统时区设置
  10. [PyTorch] 译+注:一个例子,让你明白PyTorch框架
  11. 4.正则匹配与re模块
  12. 本地 Git 文件夹显示绿色标识
  13. centos yum 安装php8 php8.0 使用remi源
  14. h5物体拖动_研究了50+个爆款H5,原来他们刷屏的套路如此简单
  15. uni-app项目(分类页)
  16. 基于PHP的招聘网站
  17. HDoj 2604 queuing
  18. Kubernetes学习之Deployment控制器
  19. 销 售 中 的 异 议
  20. 嵌入式中的BSP---BSP到底是什么?

热门文章

  1. iOS 开发比较实用的框架总结(上)
  2. HDU 5634 Rikka with Phi
  3. [HDU 1430] 魔板
  4. ubuntu16.04安装opencv3.3
  5. QML Item定位器 Anchor
  6. FAT文件系统原理详细介绍
  7. Qt制作贪吃蛇小游戏
  8. C++字符编码的查看和检测
  9. C语言获取窗口输入焦点,使按钮获得输入焦点 - rainbowcode的个人空间 - OSCHINA - 中文开源技术交流社区...
  10. C++语音识别接口快速入门(Microsoft Speech SDK)