import math
num_rows = int(input())
if num_rows % 2 != 0:
upper_mid = math.ceil(num_rows/2)
lower_mid = num_rows//2
#prints upper normal triangle
for row in range(0, upper_mid):
for col in range(upper_mid-1, row, -1):
print(end=" ")
for col in range(row+1):
print('*', end="")
for col in range(row):
print('*', end="")
print()
# prints lower inverted triangle
for row in range(0, lower_mid):
for col in range(row+1):
print(end=" ")
for col in range(lower_mid - row):
print('*', end="")
for col in range(lower_mid - row-1):
print('*', end="")
print()
else:
print("Only odd numbers!")
import math
num_rows = int(input())
if num_rows % 2 != 0:
upper_mid = math.ceil(num_rows/2)
lower_mid = num_rows//2
#prints upper normal triangle
for row in range(0, upper_mid):
for col in range(upper_mid-1, row, -1):
print(end=" ")
for col in range(row+1):
print('*', end="")
for col in range(row):
print('*', end="")
print()
# prints lower inverted triangle
for row in range(0, lower_mid):
for col in range(row+1):
print(end=" ")
for col in range(lower_mid - row):
print('*', end="")
for col in range(lower_mid - row-1):
print('*', end="")
print()
else:
print("Only odd numbers!")
This code works 100%, and prints a diamond shape star pattern. I'm a beginner in pythonPython, and wrote this by myself, so I might have wrotewritten something unnecessary and the code could be simplified, or something else. Feedback is appreciated.