Advertisement
yukcheong

Pyramid number

Jul 7th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. def solution(x,y):
  2.     ID = 1
  3.      
  4.     if x==0 or y==0:
  5.         raise ValueError
  6.    
  7.     else:      
  8.         # looking for the first number of every row
  9.         for n in range(2,y+1):
  10.             ID += 1 + (n-2)  
  11.            
  12.         # sums out all the difference
  13.         for n in range(2, x+1):
  14.             ID += (2 + (n-2)) + (y-1)
  15.         print ID
  16.    
  17. solution(0,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement