2016-10-11 60 views
-1

我想製作一個盒子,用戶在其中輸入寬度,高度,盒子應該由什麼樣的符號和填充(盒子內)。我是一個新的python編碼器,所以任何建議都會很棒,但是新手級別的響應越好,所以我可以學習,而不是跳過很遠的技術。用python製作一個盒子,用戶可以控制輸入

def main(): 
     width = print(int("Please enter the width of the box: ")) 
     height = print(int("Please enter the height of the box: ")) 
     symbol = print("Please enter the symbol for the box outline: ") 
     fill = print("Please enter the symbol for the box fill: ") 
     for a in range(width): 
      for b in range(height): 
       if i in #some condition here 
        print(symbol) 
       else: 
        print(fill) 
    main() 

我預計的輸入應該是:

width: 4 
height: 4 
symbol: # 
fill:1 
#### 
#11# 
#11# 
#### 
+1

那麼,什麼是你的代碼確切的問題?發生了什麼,你得到了什麼錯誤,......? (至少你的'或'子句似乎是錯誤的,但其他所有我們需要更多信息) – UnholySheep

+0

StackOverflow是一個網站,用於獲得有關代碼特定問題的具體問題的幫助。我會查看http://codereview.stackexchange.com/,它可能更適合您的需求。只要確保閱讀那裏的規則,就像你應該在這裏完成的那樣。這可能會被標記和關閉,因爲它不是真正在這個網站的主題。 –

+0

@UnholySheep,我要去掉或者這個條款。但原來的問題仍然存在 – chihao

回答

2
def main(): 
    # input is your friend here 
    width = input("Please enter the width of the box: ") 
    #width = print(int("Please enter the width of the box: ")) 
    # input etc.. 
    height = print(int("Please enter the height of the box: ")) 
    symbol = print("Please enter the symbol for the box outline: ") 
    fill = print("Please enter the symbol for the box fill: ") 
    #since you'll be printing rows of text you should probably flip these loops 
    for row in range(height): 
    #for a in range(width): 
     for col in range(width): 
     #for b in range(height): 
      # i ??? huh where did this come from ? 
      #if i in [0, width-1] or [0, height-1]: 
      # descriptive variables can only help 
      if row in [0,height-1] or col in [0,width-1]: 
       print(symbol) 
      else: 
       print(fill) 
+0

def main(): #輸入是這裏的朋友 width = input(「請輸入框的寬度:」) #width = print(int(「請輸入框的寬度:」)) #輸入等等。 height = print(int(「請輸入框的高度:」)) symbol = print(「請輸入框大綱的符號:」) – chihao

+0

我沒有注意,我需要用輸入來替換打印件。 – chihao

0

使用input("Enter number")從用戶獲取輸入。你應該先在高度上循環,然後在寬度上循環。不要使用新行end=""作爲print的參數進行打印。您使用i而不是ba。這就是我的想法。下次問更具體的問題。

0
def main(): 
    width = int(input("Please enter the width of the box: ")) 
    height = int(input("Please enter the height of the box: ")) 
    symbol = input("Please enter the symbol for the box outline: ") 
    fill = input("Please enter the symbol for the box fill: ") 
    dictionary = [] 
    for row in range(height): 
     for col in range(width): 
      if row in [0, height-1] or col in [0, width-1]: 
       dictionary.append(symbol) 
      else: 
       dictionary.append(fill) 

    def slice_per(source, step): 
     return [source[i::step] for i in range(step)] 
    sliced = slice_per(dictionary, width) 
    for x in range(len(sliced)): 
     print("".join(sliced[x]), end="\n") 
main() 

輸出 - 5,5,#,0

##### 
#000# 
#000# 
#000# 
#####