[enter image description here][1]I have to print a diamond pattern in Python, but the diamond is different. There are 2 input variables m and n. m represent the number of the blocks where n represents the head on that block, and if the lines on the head are greater than 2, then lines () are inside the block [Head_lines – 2 = number of ‘‘]. check the attached picture for reference
I got this code, and I still haven’t figured out how to remove the space at the end of the line.
Can someone help me solve this pattern?
It’s almost done Thanks to @SIGHUP
Dhiraj Badlani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
0
You’ll find that f-strings are very useful for this exercise. You can calculate the number of underscores based on the second parameter passed to your function.
Something like this:
def picture(m, n):
print((f" {'/\'*n} " * m)[:-1])
z = (n - 1) * 2
print(f"/ {'_'*z} \" * m)
print(f"\ {' '*z} /" * m)
print((f" {'\/'*n} " * m)[:-1])
if __name__ == "__main__":
picture(3, 5)
Output:
//// //// ////
/ ______ / ______ / ______
/ / /
//// //// ////
3