Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使输出垂直显示?_Python_Output - Fatal编程技术网

Python 如何使输出垂直显示?

Python 如何使输出垂直显示?,python,output,Python,Output,但我需要使它垂直显示 如果用户输入字母字符,如何使输出为“Maaf,hanya menerima angka 1-25”(对不起,只允许数字1-25)? 谢谢。尽量减少代码中的mod Masukkan jumlah bin antara 1-25(0 untuk berhenti): 3 1-33 :*************************************************************************************(8529) 34-6

但我需要使它垂直显示

如果用户输入字母字符,如何使输出为“Maaf,hanya menerima angka 1-25”(对不起,只允许数字1-25)?
谢谢。

尽量减少代码中的mod

Masukkan jumlah bin antara 1-25(0 untuk berhenti): 3
  1-33 :*************************************************************************************(8529)
 34-67 :*************(1302)
68-100 :*************************************************************************(7321)

有没有理由不使用绘图库?感谢您的回复,我只允许使用随机库进行数据处理欢迎使用StackOverflow!请不要将标题更改为“已回答,谢谢”。有了合适的标题,这篇文章也可能对未来的访问者有所帮助!谢谢你通知我。
Masukkan jumlah bin antara 1-25(0 untuk berhenti): 3
  1-33 :*************************************************************************************(8529)
 34-67 :*************(1302)
68-100 :*************************************************************************(7321)
import random

def print_words_vertical(lst):
    '''
        Print words in columns
        
        lst is a list of strings
        Each string is comma separated words
    '''
    words_list = [x.split(',') for x in lst]
    
    # Longest word sublist
    longest_word_list = max(words_list, key=len)
    
    # Longest individual word
    longest_word = max([word for sublist in words_list for word in sublist], key = len)
    widest_width = len(longest_word)

    # Vertical Print
    for index in range(len(longest_word_list), -1, -1):
        for sublist in words_list:
            if index < len(sublist):
                # This sublist has enough word to show at this index
                print(sublist[index].center(widest_width), end ='')
            else:
                # Insert space since we don't have a word for this column
                print(' '*widest_width, end = '')

        print()  # Newline between rows
    print()
        

Bins=1
while Bins!=0:
  Bins = input("Masukkan jumlah bin antara 1-25(0 untuk berhenti): ")
  Bins = int(Bins)                   # Preferable to use int() function to convert number to int since eval is unsafe
  if Bins==0:
    print("Done! Program selesai.")
    break
  elif Bins>1:
    x=[]
    c=random.randint(0,10000)
    for i in range(Bins):
      x.append(c)
      c=random.randint(0,10000-c)
    if sum(x)!=10000:x.append(10000-sum(x))
    else:x.append(0)
  elif Bins==1: x=[10000]
  if Bins<0 or Bins>25:
    print("Maaf, hanya menerima angka 1-25")
    continue
  tmp=-1

  # Capture bin information into a comma delimited string s
  lst = []
  for i in range(Bins):
    tmp=round(100/Bins*i)+1
    tmp1=round(100/Bins*(i+1))
    # Append bin information into string, with commas between major units
    lst.append((str(tmp)+"-"+str(tmp1)).rjust(6)+" "+","+"*,"*(x[i]//100)+"("+str(x[i])+")")
    
  
  # Vetrical print bins
  print_words_vertical(lst)
 Masukkan jumlah bin antara 1-25(0 untuk berhenti): 10
                                                                      
                                    (7701)                            
                                      *                               
                                      *                               
                                      *                               
                                      *                               
                                      *                               
                                      *                               
                                      *           (7048)              
                                      *             *                 
                      (6886)          *             *                 
                        *             *             *                 
                        *             *             *                 
                        *             *             *                 
                        *             *             *                 
                        *             *             *                 
                        *             *             *                 
 (6151)                 *             *             *                 
   *                    *             *             *                 
   *                    *             *             *                 
   *                    *             *             *                 
   *                    *             *             *                 
   *                    *             *             *                 
   *                    *             *             *                 
   *                    *             *             *                 
   *                    *             *             *                 
   *                    *             *             *                 
   *                    *             *             *           (5104)
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *                    *             *             *             *   
   *    (3000)          *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *             *             *             *   
   *      *             *    (1914)   *             *             *   
   *      *             *      *      *             *             *   
   *      *             *      *      *             *             *   
   *      *             *      *      *             *             *   
   *      *             *      *      *             *             *   
   *      *             *      *      *             *             *   
   *      *             *      *      *             *    (1376)   *   
   *      *             *      *      *             *      *      *   
   *      *             *      *      *             *      *      *   
   *      *             *      *      *             *      *      *   
   *      *             *      *      *    (980)    *      *      *   
   *      *             *      *      *      *      *      *      *   
   *      *             *      *      *      *      *      *      *   
   *      *             *      *      *      *      *      *      *   
   *      *    (513)    *      *      *      *      *      *      *   
   *      *      *      *      *      *      *      *      *      *   
   *      *      *      *      *      *      *      *      *      *   
   *      *      *      *      *      *      *      *      *      *   
   *      *      *      *      *      *      *      *      *      *   
   *      *      *      *      *      *      *      *      *      *   
  1-10  11-20  21-30  31-40  41-50  51-60  61-70  71-80  81-90 91-100