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

首先放上UP主的空间 http://space.bilibili.com/699430

大叔语言很风趣,,就是教程有点少。。。

主要学一下整体的编程的思路。

然后是教程里写的代码!

#1.猜数字游戏。

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 
#第二个游戏主要是用来学习字典的简单应用。

你可能感兴趣的:(B站看见了个很好玩的入门教学,做个记号标记下。)