ITPub博客

首页 > 应用开发 > IT综合 > 与小卡特一起学python 第1章 出发吧 1-2猜数游戏

与小卡特一起学python 第1章 出发吧 1-2猜数游戏

原创 IT综合 作者:yarking207 时间:2016-03-28 17:17:53 0 删除 编辑
import random
secret = random.randint(1,99) #随机神秘数
guess = 0  #游戏者输入的数字
tries = 0    #重试次数
print ("AHOY! I'm the Dread Pirate Roberts, and I have a secret!欢迎光临,这是一个猜数游戏!")
print ("It is a number from 1 to 99. I'll give you 6 tries.这是一个1-99的一个数字,您有六次机会!")
while guess != secret and tries < 6:
    guess = int(input("What's yer guess?请输入你的数字"))#input要转换成int 书中没有注明,所以调试时出错。
    print(guess,secret,tries) #这行是我加入,想知道当前三个的数值是多少。
    if guess < secret:
        print ("Too low,ye scurvy dog!太小了哦,请重新输入")
    elif guess  > secret:
        print("Too high,landlubber!太大了,请重新输入")
        #这行空格
    tries = tries +1
       #这行空格
if guess == secret:
    print ("Avast!Ye got it! Found my secret,ye did!太棒了,恭喜猜对了。")
else:
    print("No more guesses!Better luck next time,matey!次数用尽,游戏结束。")
    print("The sectet number was秘密数字是",secret)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/220205/viewspace-2065327/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-08-03

  • 博文量
    65
  • 访问量
    99304