亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

python學習-游戲

標簽:
Python

# coding:utf-8

#!/usr/bin/python

'''

Created on Jan 4, 2018

@author: wayne

'''

import random #导入模块

import time

def displayIntro():         #定义一个函数,不执行代码,在调用的时候才执行

        print('you are in a land full of dragons.In front of you')

        print('you see two caves.In one cave,the dragon is friendly')

        print('and will share his treasure with you the other dragon')

        print('is greedy and hungry,and will eat you on sight.')

        print()

def chooseCave():       #定义一个玩家选择要进入的1或者2的函数

        cave = ''           #创建一个新的空字符串

        while cave != '1' and cave != '2':

                '''

                                                布尔操作符,and,or,not

                and 表示:表达式全为true为true,其中一个值为False或者全为False 表达式结果为False

                >>> True and True

                True

                >>>True and False

                False

                >>> False and False

                False

                or:只要其中一个值为True 那么结果就为True ,只有两个值都为False的时候才是False

                >>>True or False

                True

                >>> True or True

                True

                >>>False or False

                False

                not :只能作用一个值,不能两个值组合在一起,not是取值的反值

                >>> not True

                False

                >>> not False

                True

                >>> not (1 ==2)

                True

                '''        

                print('which cave will you go into?(1 or 2)')

                cave = input() #接收输入值,

                return cave

def checkCave(chosenCave):  #继承chosenCave的函数值

        print('you approach the cave .....')

        time.sleep(2)

        print('it is dark and spooky.....')

        time.sleep(2)

        print('A large dragon jumps out in front of you!he opens his jaws and .....')

        print()

        time.sleep(2)

        friendlyCave = random.randint(1,2)  #随机产生一个数字,在1,2中间

        if chosenCave == str(friendlyCave): #判断输入值和随机产生的值是否一致,一致则玩家获胜,否则失败

                print('Gives you his treasure!')

        else:

                print('Gobbles you down in one bite!')

playAgain = 'yes'       #存储一个初始值,"yes"

while playAgain == 'yes' or playAgain == 'y': #判断条件是否为True

        displayIntro() #调用函数

        caveNumber = chooseCave()   #调用输入值的函数

        checkCave(caveNumber) #调用checkCave的函数

        print('Do you want to play again!(yes or no)') #判断玩家是否还要玩

        playAgain = input() #接收键盘输入的值,如果是True则循环开始

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消