zoukankan      html  css  js  c++  java
  • Python笔记1(作业)

    1、使用while循环输入 1 2 3 4 5 6 8 9 10。

    1 count=1
    2 while count<11:
    3     if count==7:
    4         count += 1
    5     print(count)
    6     count+=1

    2、求1-100的所有数的和。

    1 count=1
    2 sum=0
    3 while count<101:
    4     sum+=count
    5     count+=1
    6 print(sum)

    3、输出 1-100 内的所有奇数。

    1 count=1
    2 while count<101:
    3     print(count)
    4     count+=2

    4、输出 1-100 内的所有偶数

    1 count=2
    2 while count<101:
    3     print(count)
    4     count+=2

    5、求1-2+3-4+5 ... 99的所有数的和

    1 count=1
    2 sum=0
    3 while count<100:
    4     if count %2 == 0:
    5         sum-=count
    6     else:
    7         sum+=count
    8     count+=1
    9 print(sum)

    6、用户登陆(三次机会重试)

    要求:支持多用户登录,尝试三次登录错误后,提示用户是否继续输入,输入Y,获得三次机会,否则退出登录

    提供链表:li = [{'username':'张三','password':'123'},{'username':'李四','password':'456'},{'username':'王五','password':'789'},]

     1 li = [{'username':'张三','password':'123'},
     2     {'username':'李四','password':'456'},
     3     {'username':'王五','password':'789'},
     4       ]
     5 i=1
     6 while i<=3:
     7     username = input('请输入您的名字:')
     8     password = input('请输入您的密码:')
     9     for s in li:
    10         if username==s['username'] and password==s['password']:
    11             print(username, '登录成功')
    12             i=4
    13             break
    14     else:
    15         print('用户名或密码输入错误,请重新登录')
    16         if i==3:
    17             choice=input('继续尝试登录?请输入Y,否则退出登录:')
    18             if choice=='Y':
    19                 i=0
    20     i += 1
  • 相关阅读:
    Two Sum
    Binary Tree Preorder Traversal *
    Rotate Array
    Repeated DNA Sequences
    Symmetric Tree
    Path Sum
    Python初学——多线程Threading
    Python初学——窗口视窗Tkinter
    pyinstaller打包多个py文件和去除cmd黑框
    python获取当前路径
  • 原文地址:https://www.cnblogs.com/xingye-mdd/p/8746655.html
Copyright © 2011-2022 走看看