python学习记录3------while和if的应用-输出长方形


''' 用户输入长,宽,输出长*宽的长方形,用#输出 ''' #flag = True while True: width= None height= None try : height= int(input("请输入长:")) width= int(input("请输入宽:")) except : pass if type(height) == int and type(width) == int : #判断输入的是否是数字,若不是,重新输入 while height> 0 : i=width #需要将width赋值给i,height没循环一次,宽是要重置一次 height-=1 while i>0 : print("#",end="") #end使得print打印不直接换行 i-=1 if i==0 and height!=0: #如果i=0,则换行,当i=0且long=0时,说明结束,不需要换行 print() if height==0 :
              break #flag = False
                 else : print("错误!!请输入数字") '''-------------------------------- 缺点,如果输入长是数字,宽不是数字,那么会提示错误!!请输入数字,但是要重新输入长跟宽'''

  

posted @ 2019-09-17 19:45  fangxs666  阅读(320)  评论(0编辑  收藏  举报