day2 python全栈学习笔记

1、用户登陆

i=0
while i<3:
    i += 1
    j = 3 - i
    username = input("请输入姓名:")
    password = input("请输入密码:")

    if username == "小二" and password == "123":
        print("登陆成功")
    else:
        if username != "小二":
            print("帐户名错误")
            print("你还有%d次机会" % (j))
            if i == 3:
                answer = input("再试试?")
                if answer == "y":
                    i = 0
        elif username == "小二":
            if password != "123":
                print("密码错误")
                print("你还有%d次机会" % (j))
                if i == 3:
                    answer = input("再试试?")
                    if answer == "y":
                        i = 0
三次之后还有机会

 2、格式化输出

1 name = input('请输入姓名')
2 age = input('年龄')
3 
4 msg = "我是%s,今年%s岁" %(name,age)
5 
6 print(msg)
占位符

3、不包括88,求1-2+3-4...+99-100的和

 1 i=0
 2 sum = 0
 3 while i<100 :
 4     i += 1
 5     if i == 88 :
 6         continue
 7     elif i % 2 == 0:
 8         sum -= i
 9     else:
10         sum += i
11 print(sum)
88之后数字位置不变
 1 i = 0
 2 sum = 0
 3 while i<100 :
 4     i += 1
 5     if i == 88 :
 6         continue
 7     elif i<88 :
 8         if i % 2 == 0:
 9             sum -= i
10         else:
11             sum += i
12     else:
13         if i % 2 == 0:
14             sum += i
15         else:
16             sum -= i
17 print(sum)
18 print(i)
89占88位置,后边依次往前顶

 

posted on 2018-11-25 15:11  老毛孩  阅读(297)  评论(0编辑  收藏  举报

导航