zoukankan      html  css  js  c++  java
  • python第一次作业


    # 1、使用while循环输入 1 2 3 4 5 6 8 9 10
    1 i = 1
    2 while i < 11:
    3     if i!= 7:
    4         print(i)
    5     else:
    6         pass
    7     i+=1
    # 2、求1-100的所有数的和
    i = 1
    sum = 0
    for i in range(1,101):
        i = i+sum
        sum = 0+i
    print(sum)
    # 3、输出 1-100 内的所有奇数
    for i in range(1,101):
        if i%2 == 1:
            print(i)
        i = i+1
    # 4、输出 1-100 内的所有偶数
    i = 1
    while i < 101:
        if i%2 == 0:
            print(i)
        i +=1
    # 5、求1-2+3-4+5 ... 99的所有数的和
    sum_i = 1
    for i in range(1,101):
        if i%2 == 1:
            #print(i)
            sum_i = sum_i + i
        i = i+1
    #print(sum_i)
    j = 1
    sum_j = 2
    while j < 101:
        if j%2 == 0:
            #print(j)
            sum_j = sum_j +j
        j = j+1
    sum = sum_i - sum_j
    print("1-2+3-4+5 ... 99的所有数的和是{}".format(sum))
    print("1-2+3-4+5 ... 99的所有数的和是%s"%(str(sum)))
    print("1-2+3-4+5 ... 99的所有数的和是{0}".format(sum))
    print("1-2+3-4+5 ... 99的所有数的和是{sum}".format(sum = sum))
    # 6、用户登陆(三次机会重试)
    count = 0
    sum = 2
    username = "XF"
    password = "123456"
    while count < 3:
        usr = str(input("请输入账号:")).strip()
        psd = str(input("请输入密码:")).strip()
        if usr == username and psd == password:
            print("登录成功")
            break
        elif usr == username and psd != password:
            sum = sum - count
            print("密码错误,还有%s次输入机会"%sum)
        elif usr != username and psd == password:
            sum = sum - count
            print("无此账号,还有%s次输入机会"%sum)
        elif usr != username and psd != password:
            sum = sum - count
            print("账号名或密码错误,还有%s次输入机会"%sum)
        count = count+1






  • 相关阅读:
    JavaEE 第四周
    JavaEE 第三周
    JavaEE 第二周
    JavaEE 第一周
    js字符串方法
    javaee项目库存管理系统总结
    javaee期末团队项目库存管理系统概要信息
    JAVAEE第十一周
    JSON
    Facelets
  • 原文地址:https://www.cnblogs.com/huoyunxieshen/p/10099705.html
Copyright © 2011-2022 走看看