How to stack indices and given values

后端 未结 3 1130
遥遥无期
遥遥无期 2021-01-28 17:04
seq1_values = [5, 40, 180, 13, 30, 20, 25, 24, 29,  31,  54, 46,  42, 50,  67, 17,
           76, 33, 84, 35, 100, 37, 110, 32, 112, 15, 123, 3, 130, 42]

def get_num_va         


        
3条回答
  •  庸人自扰
    2021-01-28 17:31

    Your code seems very complex for what you're doing. You used the tag for-loop but you're using a while loop- I would recommend going with that for loop. You can loop over seq1_values, printing out all the indices, and then print a newline, then go through one more time and print all the values:

    seq1_values = [5, 40, 180, 13, 30, 20, 25, 24, 29,  31,  54, 46,  42, 50,  67, 17,
               76, 33, 84, 35, 100, 37, 110, 32, 112, 15, 123, 3, 130, 42]
    
    
    def main():
        for s in range(0,len(seq1_values)):
            print("|",str(s).rjust(3),end="")
        print("")                                   # Gives us a new line
        for s in range(0,len(seq1_values)):
            print("|",str(seq1_values[s]).rjust(3),end="")
    
    main()
    

提交回复
热议问题