zoukankan      html  css  js  c++  java
  • Python练习-2

    #1、使用while循环输入 1 2 3 4 5 6 8 9 10
    
    count = 0
    while count < 10:
        count += 1  # count = count + 1
        if count == 7:
            print(' ')
        else:
            print(count)
    count = 0
    while count < 10:
        count += 1  # count = count + 1
        if count == 7:
            continue
        print(count)
    #3、输出 1-100 内的所有奇数
    #方法一:
    count = 1
    while count < 101:
        print(count)
        count += 2
    #方法二:
    count = 1
    while count < 101:
        if count % 2 == 1:
            print(count)
        count += 1

      

    #5、求1-2+3-4+5 ... 99的所有数的和
    sum = 0
    count = 1
    while count < 100:
        if count % 2 == 0:
            sum = sum - count
        else:
            sum = sum + count
        count += 1
    print(sum)
    #6、用户登陆(三次机会重试)
    #input 心中有账号,密码 while
    
    i = 0
    while i < 3:
        username = input('请输入账号:')
        password = int(input('请输入密码:'))
        if username == '咸鱼哥' and password == 123:
            print('登录成功')
        else:
            print('登录失败请重新登录')
        i += 1
    #格式化输出
    # % s d
    # name = input('请输入姓名')
    # age = input('请输入年龄')
    # height = input('请输入身高')
    # msg = "我叫%s,今年%s 身高 %s" %(name,age,height)
    # print(msg)
    """
    name = input('请输入姓名:')
    age = input('请输入年龄:')
    job = input('请输入工作:')
    hobbie = input('你的爱好:')
    
    msg = '''------------ info of %s -----------
    Name  : %s
    Age   : %d
    job   : %s
    Hobbie: %s
    ------------- end -----------------''' %(name,name,int(age),job,hobbie)
    print(msg)
    """
    name = input('请输入姓名')
    age = input('请输入年龄')
    height = input('请输入身高')
    msg = "我叫%s,今年%s 身高 %s 学习进度为3%%s" %(name,age,height) # %%转译%
    print(msg)
    count = 0
    while count <= 5 :
        count += 1
        if count == 3:break
        print("Loop",count)
    
    else:
        print("循环正常执行完啦")
    print("-----out of while loop ------")
  • 相关阅读:
    如何找到bug(8): SequentialInputHandler::run()取数逻辑
    如何找到bug(7): 检查事例完整性的逻辑
    如何寻找bug(6)
    如何寻找bug(5)
    c++ : 静态成员函数
    c++:静态数据成员
    如何打开某一个包的debug
    如何寻找bug(4)
    如何找bug(3)
    Oracle学习系类篇(二)
  • 原文地址:https://www.cnblogs.com/LXL616/p/10622310.html
Copyright © 2011-2022 走看看