• Some question code


    # 使用while和for循环分别打印字符串s=’asdfer’中每个元素。

    # s = "asdfer"
    #
    # for i in s:
    #     print(i)
    #
    # i = 0
    # while i < len(s):
    #     print(s[i])
    #     i += 1

    # 如:content = input(‘请输入内容:’) # 如用户输入:5+9或5+ 9或5 + 9,然后进行分割再进行计算。

    # sum = 0
    # content = input('<<<')
    #
    # # index = content.find("+")
    # # a = int(content[0:index])
    # # b = int(content[index + 1:])
    # # print(a + b)
    # for i in content.split("+"):
    #     sum += int(i)
    # print(sum)

    # 任意输入一串文字+数字 统计出来数字的个数

    # s = input("<<<")
    # num = 0
    # for i in s:
    #     if i.isdigit():
    #         num += 1
    # print(num)

    # # 循环录入字符串

    1 # # allthing = ['123']
    2 # # right = 'q'
    3 # # while 1:
    4 # #     add = input('你想输入什么(q退出): ')
    5 # #     if add.lower() == 'q'.lower():
    6 # #         break
    7 # #     else:
    8 # #         allthing.append(add)
    9 # # print(allthing)

    # 打印列表中列表的元素(列表中还有列表)

     1 li = [1, 2, 3, 5, 'alex', [2, 3, 4, 5, 'taibai'], 'afds']
     2 for i in li:
     3     if type(i) == list:
     4         for j in i:
     5             print(j)
     6     else:
     7         print(i)
     8 
     9 for i in range(len(li)):
    10     if type(li[i]) == list:
    11         for j in li[i]:
    12             print(j)
    13     else:
    14         print(li[i])

     # 计算 1 - 2 + 3 ... + 99 中除了88以外所有数的总和

    # i = 0
    # sum = 0
    # while i < 99:
    #     i += 1
    #     if i == 88:
    #         continue
    #     elif i % 2 != 0:
    #         sum += i
    #     else:
    #         sum -= i
    #
    # print(sum)

    # 计算 1 - 2 + 3 ... -99 中除了88意外所有数的总和

     1 i = 0
     2 j = -1
     3 sum = 0
     4 while i < 99:
     5     i += 1
     6     if i == 88:
     7         continue
     8     else:
     9         j *= -1
    10         sum += i * j
    11 print(sum)

    # ⽤户登陆(三次输错机会)
    # 且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化)

     1 un = 0  # 记录帐号输错的次数
     2 up = 0  # 记录密码输错的次数
     3 state = True    # 程序当前状态
     4 username = 'admin'
     5 password = '123456'
     6 
     7 while state:
     8     input_username = input("Please input your username(you still have %d times): "%(3 - un))
     9     if input_username == username:
    10         input_password = input("Please input your password(you still have %d times): " %(3 - up))
    11         if input_password == password:
    12             print('Loading successfully.')
    13         else:
    14             up += 1
    15             if up == 3:
    16                 print("Your ID was locked.")
    17                 break
    18             else:
    19                 print("Your password is error, please check it then input again: ")
    20     else:
    21         un += 1
    22         if un == 3:
    23             print("Your ID was locked.")
    24             break
    25         else:
    26             print("Your username is error, please check it then input again: ")

    # 循环录入,接收到退出按键退出

    1 allthing = ['123']
    2 right = 'q'
    3 while 1:
    4     add = input('你想输入什么(q退出): ')
    5     if add.lower() == 'q'.lower():
    6         break
    7     else:
    8         allthing.append(add)
    9 print(allthing)

     

    # 查找列表li中的元素,移除每个元素的空格,
    # 并找出以’A’或者’a’开头,并以’c’结尾的所有元素,
    # 并添加到一个新列表中,最后循环打印这个新列表。

     1 li = ['taibai ', 'alexC', 'AbC ', 'egon', ' Ritian', ' Wusir', '  aqc']
     2 b = []
     3 # for i in li:
     4 #     s = i.strip()
     5 #     if (s.startswith("A") or s.startswith('a')) and s.endswith('c'):
     6 #         b.append(s)
     7 # for i in b:
     8 #     print(i)
     9 # for i in li:
    10 #     s = i.strip()
    11 #     if s[0].upper() == 'A' and s[-1] == "c":
    12 #         b.append(s)
    13 # for i in b:
    14 #     print(i)

    # 开发敏感词语过滤程序,提示用户输入评论内容,如果用户输入的内容中包含特殊的字符:
    # 敏感词列表 li = ["苍老师","东京热",”武藤兰”,”波多野结衣”]
    # 则将用户输入的内容中的敏感词汇替换成***,并添加到一个列表中;
    # 如果用户输入的内容没有敏感词汇,则直接添加到上述的列表中。

    # li=["苍老师","东京热","武藤兰","波多野结衣"]
    # new_li= []
    # info = input("评论")  # 苍老师,东京热 法律框架第三
    # for i in li:
    #     if i in info:
    #         l = len(i)
    #         info=info.replace(i,'*'*l)
    # new_li.append(info)
    # print(new_li)
    
    # print("Welcome! -1 exit the program")
    # li = ["苍老师", "东京热", "武藤兰", "波多野结衣"]
    # b = []
    # l = 0
    # while 1:
    #     sensitive = input("<<<")
    #     if sensitive == "-1":
    #         break
    #     if sensitive in li:
    #         l = len(sensitive)
    #         sensitive = sensitive.replace(sensitive, "*" * l)
    #     b.append(sensitive)
    # print(b)

    # 重要 计算输入字符串中数字团的个数

     1 # fhdklah123rfdj12fdjsl3    '       123     12    13'
     2 
     3 # info = input('>>>').strip()
     4 # for i in info:
     5 #     if i.isalpha():
     6 #         info = info.replace(i," ")
     7 # l = info.split()
     8 # print(len(l))
     9 
    10 # 升级版
    11 s = input('<<<')
    12 for i in s:
    13     if not(i.isdigit()):
    14         s = s.replace(i, ' ')
    15 s = s.split()
    16 print(len(s))
  • 相关阅读:
    spring hibernate 调用存储过程
    Mybatis mapper配置
    流量红包算法
    带搜索的下拉框Chosen
    生成二维码
    Linux netlink机制
    OpenFlow Switch学习笔记(七)——Matching Fields
    Hierarchical Token Bucket
    OpenvSwitch架构
    Examining Open vSwitch Traffic Patterns
  • 原文地址:https://www.cnblogs.com/Rainm/p/9609290.html
Copyright © 2020-2023  润新知