+ 2
Playing with I and j!!
Hi. So I want to write a very simple program so if we enter an odd number as an input it gives us to rhombuses next to each other(large diameter equal to the entrance) Example: Input: 5 Outpapp * * *** *** ********** *** *** * * I wrote the program but for the same input mine is: * * * * * * * * * * * * * * * * * * What's the problem with my code? For example I tried to delete the space or adding another * and it was ok but for the first and last star we will have to 2 stars too! My code: https://code.sololearn.com/cAO2K3ndNcm1/?ref=app
2 ответов
+ 5
Correct code,
def main(a):
for i in range(a):
print(' '*(a-i-1)+'*'*(i+(i+1)), ' '*(a-i-1)+'*'*(i+(i+1)))
for j in range(a-1,0,-1):
print(' '*(a-j)+'*'*((j*2-1)), ' '*(a-j)+'*'*(j*2-1))
a = int(input())
a =a//2+1
main(a)
+ 2
def main(a):
for i in range(a):
print(' '*(a-i-1)+'*'*((i+1)*2-1), ' '*(a-i-1)+'*'*((i+1)*2-1))
for j in range(a-1,0,-1):
print(' '*(a-j)+'*'*(j*2-1), ' '*(a-j)+'*'*(j*2-1))
a = int(input())
a =a//2+1
main(a)