Q. Print a cross using a single Nested For loop in python
#codes are high_lighted in green
for i in range(1,6): #value of i will go from (1,6)
for j in range(1,6): # value of j goes from (1,6)
if (i == j or i + j == 6): #if value of i is equal to j or if sum i and j is equal to 6 then print *
print("*", end = " ")
else:
print(" ", end = " ") # print spaces where conditions are not specified
print() # print func to get the pointer on next line
output:

Comments
Post a Comment