Python pattern programs morioh.com/p/c0fe4adbcf73 #python #programming #developer #morioh #programmer #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming #pythonquiz #ai #ml #machinelearning #datascience
@Python_Dv def print_diamond(n): for i in range(n): print(" "*(n-i-1) + "*"*(2*i+1)) for i in range(n-2, -1, -1): print(" "*(n-i-1) + "*"*(2*i+1)) print_diamond(10) #the code will print a diamond with 10 rows from single asterisk at the top to increasing by two 👇
@Python_Dv Can anyone explain the logic behind these algorithms?
@Python_Dv def dlamond_pattern(n): for i in range(1, n + 1): print(" " * (n - i) + "* " * i) for i in range(n - 1, 0, -1): print(" " * (n - i) + "* " * i) dlamond_pattern(5)
@Python_Dv def triangule_pattern(n): for i in range(1, n + 1): print(" " * (n - i) + "* " * i) triangule_pattern(5)
@Python_Dv Can someone explain how 2ñd one works?