zoukankan      html  css  js  c++  java
  • Python老男孩 day09 练习题

    练习题1:使用while循环输入 1 2 3 4 5 6     8 9 10

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

    练习题2:求1-100的所有数的和

    1 s=0
    2 a=1
    3 while a<101:
    4     s=s+a
    5     a=a+1
    6 
    7 print(s)

    练习题3:输出 1-100 内的所有奇数

    1 a=1
    2 while a<101:
    3     if a%2==1:
    4        print(a)
    5     else:
    6         pass
    7     a=a+1  

    练习题4:输出 1-100 内的所有偶数

    1 a=1
    2 while a<101:
    3     if a%2==0:
    4        print(a)
    5     else:
    6         pass
    7     a=a+1  

     练习题5:求1-2+3-4+5 ... 99的所有数的和

     1 s=0
     2 n=1
     3 while n<100:
     4     temp=n%2
     5     if temp==0:
     6         s=s-n
     7     else:
     8         s=s+n
     9     n=n+1
    10 print(s)

     练习题6:用户登陆(三次机会重试)

     1 print('用户登录界面')
     2 
     3 id='root'
     4 passwd='123456'
     5 count=0
     6 
     7 while count<3:
     8     inputid=input('请输入用户名')
     9     inputpasswd=input('请输入密码')
    10     if inputid==id and inputpasswd==passwd:
    11         print('登陆成功!')
    12         break
    13     else:
    14         print('用户名或密码错误')
    15     count=count+1
    16     
  • 相关阅读:
    Fiddler-代理-过滤-弱网测试
    POJ2186 Popular Cows
    POJ3264 Balanced Lineup
    多模式串字符串匹配模板题
    Intersecting Lines
    实现堆结构
    OpenJuege 兔子与星空
    拓扑排序
    POJ3635 Full Tank?
    OpenJudge Cartesian Tree
  • 原文地址:https://www.cnblogs.com/zhuhemin/p/9061622.html
Copyright © 2011-2022 走看看