• 2019.11.04


    1、使用while循环输出 1 2 3 4 5 6  8 9 10

    count = 0

    while count < 10:
    count += 1
    if count == 7:
    continue


    print(count)

    运行结果为:1 2 3 4 5 6 8 9 10 

    2、求1-100的所有数的和

    a = 0

    for i in range(1,101):
    a = a+i

    print(a)

    运行结果为:5050

    3、输出1-100内的所有奇数

    n = 1
    while n<101:
    if n % 2 == 0:
    n = n + 1
    else:
    print(n)
    n = n + 1

    4、输出1-100内的所有偶数

    n = 1
    while n<101:
    if n % 2 == 0:
    print(n,end=" ")
    n = n + 1
    else:
    n = n + 1

    5、求1-2+3-4+5、、、99的所有数的和

    num = 0
    for i in range(100):
    if i % 2 == 0:
    num = num - i
    else:
    num = num + i

    print(num)

    6、猜年龄游戏

    、、、python

    要求:

    1、允许用户最多尝试3次

    2、每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y,就继续让其猜3次,以此往复,如果回答N或你,就退出程序

    3、如果猜对了,就直接退出

    age = 10
    count = 0
    numb = 0
    tag = True
    Y = ['Y','y']
    N = ['N','n']
    while tag:
    count = 0
    while count<3:
    num_inp = input("please give your age>>:")
    num_inp = int(num_inp)
    if num_inp == age:
    print("猜对了")
    tag = False
    break
    else:
    print("猜错了")
    count+=1
    if count == 3:
    ord = input ("continue? Y/N>>:")
    if ord in Y:
    tag = True
    elif ord in N:
    tag = False

    7、运用所学知识,打印以下图案:

    、、、python

           *

          ***

         *****

        *******

       *********

    、、、

    print("'

           *

          ***

         *****

        *******

       *********

    ''')

    list = ["    *","   ***","  *****"," *******","*********"]

    for i in list:
    print(i)

     

     

  • 相关阅读:
    VMWare中Red Hat Enterprise Linux 6与Windows XP共享文件夹/共享目录
    PetShop 4.0的数据库
    Eclipse安装Perl插件
    安装GCC for Red Hat Enterprise Linux Server release 6(64位)
    下载 Microsoft .NET Pet Shop 4.0
    一步一步安装 Microsoft .NET Pet Shop 4.0
    Visual Studio 2008安装ASP.NET MVC 2 RTM
    HTML标签大全(常用)
    换了个公司
    Counterfeit Dollar(poj1013暴力枚举)
  • 原文地址:https://www.cnblogs.com/medigrat/p/11792741.html
Copyright © 2020-2023  润新知