python day2

Posted ice777

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python day2相关的知识,希望对你有一定的参考价值。

技术分享图片
from datetime import datetime
odds=[1,3,5,7,9,11,13,15,17,19,
      21,23,25,27,29,31,33,35,37,39,
      41,43,45,47,49,51,53,55,57,59]
for i in range(60):
    import time
    import random
    time.sleep(random.randint(1,60))
    right_this_minute=datetime.today().minute
    if right_this_minute in odds:
        print("This minute seems a little odds.")
    else:
        print("Not an odd minute.")
View Code

优化

from datetime import datetime
import time
import random
odds=[1,3,5,7,9,11,13,15,17,19,
      21,23,25,27,29,31,33,35,37,39,
      41,43,45,47,49,51,53,55,57,59]
for i in range(5):

    right_this_minute=datetime.today().minute
    if right_this_minute in odds:
        print("This minute seems a little odds.")
    else:
        print("Not an odd minute.")
    wait_time=random.randint(1,50)
    print(wait_time)
    time.sleep(wait_time)

 

以上是关于python day2的主要内容,如果未能解决你的问题,请参考以下文章

python修炼之路-day2

(转)Python作业day2购物车

python攻克之路day2

老男孩Python 课堂笔记_Day2

python基础1 day2

python 学习 day2