• 数字金字塔


    num = eval(input("请输入一个整数:"))
    for i in range(1, num + 1):
        for j in range(num-i, 0, -1):
            print(" ", end="	")
        for j in range(i, 1, -1):
            print(j, end="	")
        for j in range(1, i+1):
            print(j, end="	")
        print(" ")

    row = int(input("请输入行数:"))
    num = 1
    sum = 0
    for i in range(1, row + 1):
        for j in range(row - i, 0, -1):
            print(" ", end="	")
    
        for j in range(1, i + 1):
            print(num, end="	")
            num *= 2
            sum = num
        num = 1
        sum //= 2
        for j in range(2, i + 1):
            print(sum//2, end="	")
            sum //= 2
    
        print("")

     

    pattern = input("请输入你要选择的模式:")
    while True:
        if pattern == "A":
            row = eval(input("请输入行数:"))
            for i in range(1, row + 1):
                for j in range(1, i+1):
                    print(j, end=" ")
                print("")
    
        elif pattern == "B":
            row = eval(input("请输入行数:"))
            for i in range(1, row + 1):
                for j in range(1, row - i + 2):
                    print(j, end=" ")
                print("")
    
        elif pattern == "C":
            row = eval(input("请输入行数:"))
            for i in range(1, row + 1):
                for j in range(row - i, 0, -1):
                    print(" ", end=" ")
                for j in range(i, 0, -1):
                    print(j, end=" ")
                print("")
    
        elif pattern == "D":
            row = eval(input("请输入行数:"))
            for i in range(1, row + 1):
                for j in range(1, i):
                    print(" ", end=" ")
                for j in range(1, row - i + 2 ):
                    print(j, end=" ")
                print("")
    
        elif pattern == "退出":
            break
        else:
            pattern = input("输入错误,请从新输入")
  • 相关阅读:
    java MVC设计模式探究——mvc在JAVA应用程序中的应用
    datagridview 的Columns 点击列标题 禁止排序
    组合键事件
    对一段视频,采帧(总结)
    datagridview中加入checkbox列,全选问题
    微软的RDLC报表(转)
    Linq to sql直接执行sql语句(转)
    获取当月的第1天
    AxWindowsMediaPlayer的详细用法
    DataSet
  • 原文地址:https://www.cnblogs.com/wang102030/p/9218987.html
Copyright © 2020-2023  润新知