Properly formatted multiplication table

前端 未结 5 1509
青春惊慌失措
青春惊慌失措 2021-02-15 11:11

How would I make a multiplication table that\'s organized into a neat table? My current code is:

n=int(input(\'Please enter a positive integer between 1 and 15:          


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 11:37

    Or you could just do this (not as simplistic as the others but it works):

    def main():
    
        rows = int(input("Enter the number of rows that you would like to create a multiplication table for: "))
        counter = 0
        multiplicationTable(rows,counter)
    
    def multiplicationTable(rows,counter):
    
        size = rows + 1
    
        for i in range (1,size):
            for nums in range (1,size):
                value = i*nums
                print(value,sep=' ',end="\t")
                counter += 1
                if counter%rows == 0:
                    print()
                else:
                    counter
    main()
    

提交回复
热议问题