简单试题

简单试题

  1. 给定验证码长度n,生成随机验证码,验证码由数字、字母组成(参考chr()内置方法)

    import random
    
    def yanzhengma(n):
        for i in range(n):
            s = random.randint(1, 3)
            if s == 1:
                print(chr(random.randint(48, 57)), end='')
            if s == 2:
                print(chr(random.randint(65, 90)), end='')
            if s == 3:
                print(chr(random.randint(97, 122)), end='')
    yanzhengma(10)
    
  2. 打印进度条

    import time
    
    def line(n):
        start = time.perf_counter()
        for i in range(n + 1):
            # (f'\r{},end='')实现单行刷新字符串,依次覆盖前面的字符串
            print(f'\r{((i / n) * 100): ^3.1f}%[{"#" * i}->{"." * (n - 1 - i)}]  {time.perf_counter() - start:.2f}s',end='')
            time.sleep(0.1)
    line(int(input("输入一个整数:")))
    
posted @ 2019-08-15 16:55  SweetJack  阅读(109)  评论(0编辑  收藏  举报