Well I am trying to print alphabet "R" using for loop and if-else condition is i dont understand that why i have to use an elif statement as i couldn't run the code using only if statement. if try to put the elif content in if it doesn't work.
a=4
b=2
for i in range(7):
for j in range(5):
if (j==0) or ((j==4)and (0<i<3)) or ((i==0 or i==3) and (4>j>0)) :
print("R",end=" ")
elif (i==a and j==b) and j>0:
print("R",end=" ")
a+=1
b+=1
else:
print(" ",end=" ")
print()
This code is working fine
a=4
b=2
for i in range(7):
for j in range(5):
if (j==0) or ((j==4)and (0<i<3)) or ((i==0 or i==3) and (4>j>0)) or ((i==a and j==b) and j>0):
print("R",end=" ")
a+=1
b+=1
else:
print(" ",end=" ")
print()
I cannot make R pattern with this code like below.
"""R R R R
R R
R R
R R R R
R R
R R
R R """
Aucun commentaire:
Enregistrer un commentaire