Home > Back-end >  Python, numerical triangle with a few prints, and mostly loops and ifs
Python, numerical triangle with a few prints, and mostly loops and ifs

Time:07-06

I haven't come even close, this is the way it should be displayed:




100
200   202
300   304   308
400   406   412   418
 …
 …
 …


900   916   932      …              1028


This is what I have been trying so far:

for i in range(100,1000,100):
  
  for j in range(100,1000,100):
    

  
    print(i,"  ",end="")
  
  
  print("")
  







  

x=0
for i in range(1,10,1):
  x =2
  for j in range(1,10,1):
    x =2
    

    print(x,"  ",end="")
  x=0  
  
  
  print("")
  






for i in range (10):

  for j in range(10):


      x=(j*2 (i*2*j))
    
      print(x,"  ",end="")

 
      
  print("")  











  for i in range(100,1000,100):
  
    for j in range(100,1000,100):
    

  
      print(i,"  ",end="")
  
  
  print("")
  

CodePudding user response:

try this:

for index, i in enumerate(range(100, 1000, 100)):
    num = i
    for j in range(index   1):
        print(num, end=" ")
        num  = index * 2
    print()

OUTPUT:

100 
200 202 
300 304 308 
400 406 412 418 
500 508 516 524 532 
600 610 620 630 640 650 
700 712 724 736 748 760 772 
800 814 828 842 856 870 884 898 
900 916 932 948 964 980 996 1012 1028
``

CodePudding user response:

      for i in range(100,100 1,1):
        print(i,"  ",end="")
      print("")
      
      for i in range(200,202 1,2):
        print(i,"  ",end="")
      
      print("")
      
      for i in range(300,308 1,4):
        print(i,"  ",end="")
      
      print("")
      
      for i in range(400,418 1,6):
        print(i,"  ",end="")
      
      print("")
        
      
      for i in range(500,532 1,8):
        print(i,"  ",end="")
      
      print("")
      
      
      for i in range(600,650 1,10):
        print(i,"  ",end="")
      
      
      
      print("")
      
      
      
      for i in range(700,772 1,12):
        print(i,"  ",end="")
      
      
      
      print("")
      
      
      
      
      for i in range(800,898 1,14):
        print(i,"  ",end="")
      
      
      
      print("")
      
      
      
      
      
      
      
      for i in range(900,1028 1,16):
        print(i,"  ",end="")
      
      print("")
      
      
  • Related