zoukankan      html  css  js  c++  java
  • 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位置,后边依次往前顶
  • 相关阅读:
    python-IO编程
    DNS解析流程
    python-模块
    HTTP协议
    python-函数式编程
    nmap扫描结果的6种端口状态
    python-高级特性
    python-函数
    python-基础
    上传之路
  • 原文地址:https://www.cnblogs.com/laomaohai/p/10015721.html
Copyright © 2011-2022 走看看