• python#父与子编程之旅-11嵌套与可变循环


    for multiplier in range(5,8):
      for i in range(2,11):
        print(i,"x",multiplier,"=",i*multiplier)

    #可变循环

    numstars=int(input("请输入你希望的星:"))
    for i in range(1,numstars+1):
      print("*")

    #可变嵌套循环 

    numLines = int(input("请输入带星的行有几个"))                     
    numStars = int(input("请输入一行有几颗星"))
    for line in range(0,numLines):
      for star in range(0,numStars):
        print("*",end="")
      print()

    #先打印 行,打印一行的时候打印星星,打印了规定数量星星后,end=""(python3)换行,再按要求打印下一行。。。。。,最后完成打印到规定的行,即可完成打印


    """numLines = int(input("请输入带星的行有几个"))
    numStars = int(input("请输入一行有几颗星"))
    for line in range(0,numLines):
    for star in range(0,numStars):
    print("*",end=""),
    print("")"""

    numBlock = int(input("有多少白块"))
    numLines = int(input("请输入带星的行有几个"))
    numStars = int(input("请输入一行有几颗星"))
    for block in range(0,numBlock):
      for line in range(0,numLines):
        for star in range(0,numStars):
          print("*",end=""),#这里是打印每行星星的数量
        print("")#这里是打印多少行 print("",end="")
      print("")#这里是分块 注意缩进的使用 print("")

    numBlock = int(input("有多少白块"))
    for block in range(1,numBlock+1):
      for line in range(1,block*2):
        for star in range(1,(block+line)*2):
          print("*",end=""),#这里是打印每行星星的数量
        print("")#这里是打印多少行 print("",end="")
      print("")#这里是分块 注意缩进的使用 print("")

    for i in range(1,6):
        print("Hi,Warrren")
    
    
    print("hi,warren"*6)
    
    
    for  i in range(1,8):
        print
        print('i=',i)
        print('hello, how')
        if i == 3:
            continue
        print('are you today')
    #continue的用法
    
    
    for i in range(1,6):
        print('i=',i)
        print('hello,how')
        if i ==3:
            break
        print('are you  today')
        
    #break的用法
    
    
    for i in range (1, 6, 2):
        print("Hi, Warren")
    
    range(8)
    
    
    suzhi = int(input("Which multiplication table would you like?"))
    for i in range(1,13):
        print(suzhi,"x",i,"=",suzhi*i)
    
    
    suzhi = int(input("Which multiplication table would you like?"))
    i =1
    while i >0 and i<13:
        print(suzhi,"x",i,"=",suzhi*i)
        i = i+1
        
    suzhi = int(input("Which multiplication table would you like?"))
    while suzhi >0 and suzhi<13:
        print(suzhi,"x",i,"=",suzhi*i)
        
    

      

  • 相关阅读:
    从语料中找出低频词-去除无用信息
    pytorch seq2seq模型示例
    An Open-Source Package for Knowledge Embedding- 知识嵌入为人机交互做支撑
    jiagu-工具使用
    多线程操作数据
    pycharm安装pytorch失败的问题
    模型区分度衡量指标-KS值
    jstree: 获得根节点,checkbox事件处理
    jquery:删除第一个子元素
    js:如何在iframe重载前执行特定动作
  • 原文地址:https://www.cnblogs.com/yescarf/p/11736479.html
Copyright © 2020-2023  润新知