Lesson 8 python practical operation item (2 modules used)

这节主要介绍 time,random模块;不用死记。首先说一下什么是模块。。。
    import time  有些朋友,开始比迷惑的,但是后面聊到类(属性,方法),包会好一点,我们这里没这么快说到,慢慢来,但是为了方便你记忆。。。最及简单的是.....
    你知道 x.py是你写的python脚本;如果你在同一个目录下 定义了另外一个 time.py。你import time就直接调用了(这也是,我们需要注意的,定义x.py时候名字不要跟自带的模块名字,第3方模块一样的名字,除非你自己想重写他的模块。。。。牛逼)

    import time  ###导入time的模块,time.py文件的 变量(属性);函数(方法)都可以使用。。。。
    import random ###导入随机数模块。

    print(time.time())  ###打印现在的 时间戳。。。如何转换?搜索一下吧。
    time.sleep(3)    ###睡3秒

    print(random.randint(1,100))  ###是不是打印一个 1 到 100 的整数?
    number = range(1,100)   ###number 变成一个列表了。
    print(random.sample(number,3)) ###是不是抽了3个数字?

    ####################我们模拟一个打架吧。。。
    people_a_life = random.randint(150,200)
    people_b_life = random.randint(150,200)

    people_a_kill_power = random.randint(50,80)
    people_b_kill_power = random.randint(50,80)

    print("打手1\n 血量:%s 杀伤力:%s"%(people_a_life,people_a_kill_power))
    time.sleep(2)
    print("打手2\n 血量:%s 杀伤力:%s"%(people_b_life,people_b_kill_power))

    while people_a_life >= 0 and people_b_life >=0:
        people_b_life = people_b_life -people_a_kill_power
        print("开始 打手1的***:%s, 打手2:%s"%(people_a_kill_power,people_b_life))
            time.sleep(2)
            people_a_life = people_a_life -people_b_kill_power
        print("开始 打手1的***:%s, 打手2:%s"%(people_b_kill_power,people_a_life))
            time.sleep(1)

    if people_a_life > people_b_life:
        print("打手1 win")
    elif     people_b_life > people_a_life:
        print("打手2 win")
    else:
        print("打平")

#### I believe you finish, they have a more solid, and this lesson, we review the
Print ()
\ ## escape the n-symbol
% s ### placeholders
people_a_life ### variables

Increasing the
import time time module the time.time (); the time.sleep (. 3)
Import module Random Random random.randint (1,10) taking random numbers. . . . . . . . . .

Is not very motivated, I learn. . . . To lay the foundation, do what is good, what mainly? debugging. .

Debugging process. . . . Novice take the time to actually spend time debugging of code staff is, then the subsequent repair bug ...... quality is very important. . . . A qualified product manager, is very important. . . . . . . .

Guess you like

Origin blog.51cto.com/323248/2426998