day01_习题练习

#1、使用while循环输入1 2 3 4 5 6   8 9 10
count = 0
while count<10:
    count = count + 1
    if count == 7:
        print(' ')
    else:print(count)
#2、使用while循环输入1 2 3 4 5 6 8 9 10
count = 0
while count<10:
    count = count + 1
    if count == 7:
        continue
    else: print(count)
#3、输出1-100内所有奇数
#方法一
 count = 1
 while count < 101:
    print(count)
   count = count + 2
#方法二
count = 1
 while count < 101:
       if count % 2 == 1:
         print(count)
       count = count + 1
#求1+2+3+4+5....99的所有数的和
 sum = 0
 count = 1
 while count < 100:
     sum = sum + count
     count = count + 1
 print(sum)
#求1-2+3-4+5....99的所有数的和
 count = 1
 sum = 0
while count < 100:
     if count % 2 == 0:
        sum = sum - count
    else:
         sum = sum + count
    count = count + 1
 print(sum)
#用户登录(三次机会重试)
i = 0
while i < 3:
    username = input('请输入账号:')
    password = int(input('请输入密码:'))
    if username == '张三' and password == 123 :
        print('登录成功')
    else:
        print('登录失败')
    i = i + 1
注意:中英文区分;“=”代表赋值、“==”代表等于

  

上一篇:Day01


下一篇:前端(day01)html