B站看见了个很好玩的入门教学,做个记号标记下。

</pre>首先放上UP主的空间 http://space.bilibili.com/699430<p></p><p>大叔语言很风趣,,就是教程有点少。。。</p><p>主要学一下整体的编程的思路。</p><p></p><p>然后是教程里写的代码!</p><p></p><p>#1.猜数字游戏。</p><p></p><pre name="code" class="python">import random

number = random.randint(1,100)
guess_time = 0
game_not_end = True

while game_not_end:
    guess_time = guess_time+1
    playerinput = int(raw_input("please enter your number(this is {0} time): ".format(guess_time)))
    if playerinput == number:
        print "You win !"
        game_not_end = False 
    elif playerinput > number:
        print "too large !"

    else:
        print "too small !"



#2.摇骰子比大小

import random

def roll(n):
    number = []
    for i in range(n):
        randnum = random.randint(1,6)
        number.append(randnum)

    return number


time = int(raw_input("how many time do you want : "))

com = {'hp':5}
player ={'hp':5}

while 1:

    com['result'] = roll(time)
    player['result'] = roll(time)
    print com
    print player

    if sum(com['result']) > sum(player['result']):
        print "COM win !"
        player['hp'] -=1
    else:
        print "PLAYER win !"
        com['hp'] -=1

    if com['hp'] <=0 or player['hp'] <=0:
        break 
#第二个游戏主要是用来学习字典的简单应用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值