I am learning myself the different language in Python. I am giving myself a practice to do all of eight different way by using the 'x' as I call a "star". I have a basic experience with C programming before.
For number 1. I matched the number two, but I tried to change the signs with negative (-) and positive (+) for col -= 1
or col += 1
but it seems like looping forever. I also tried the different sign from +=
to -=
in row+=1
, but again it is the same loops too. In same row, I thought to find a different way to change from 1
to -1
won't work either. I couldn't figure it out.
For number 3, I wanted to fill the spaces in the asterisk with "0" in different print(' ', end =" ")
, but either way it is just showing the '0' from outside of 'x', but it seems like I am really close to end.
For number 5, I am trying to add a few spaces to make the upside down pyramid with "x", but with those space and stars I can change the signs to extra spaces and stars, but not really sure how.
For number 6, 7, and 8... it is seems likely an impossible due to the only limited numbers for row is zero(0)/one(1) and max is six (6). Any help will be more appreciated to see what the codes looks like the expectation result.
Current Code:
print("1.")
row = 1
max = 6
while(row < max):
col = 0
while(col < max):
print(' ', end = " ")
col += 1
col = 0
while(col < row):
print('x', end=' ')
col -= 1
print("")
row+= 1
print("2.")
row = 1
max = 6
while(row < max):
col = 0
while(col < max):
print(' ', end = " ")
col += 1
col = 0
while(col < row):
print('x', end=' ')
col += 1
print("")
row+=1
print("3.")
row = 1
max = 6
while(row < max):
col = 0
while(col < max):
print(' ', end='0')
col += 1
col = 0
while(col < row):
print('x', end=' ')
col += 1
print(" ")
row+=1
print("4.")
row = 1
max = 6
while(row < max):
col = 0
while(col < max - row - 1):
print(' ', end=' ')
col += 1
col = 0
while(col < row):
print('x', end=' ')
col += 1
print(" ")
row+=1
print("5.")
row = 0
num = 6
while (row < num):
space = num-row-1
while (space>0):
print(' ', end=" ")
space = space-1
star = row+1
while (star>0):
print("x", end=" ")
star = star-1
print(" ")
row = row+1
print('6.')
row = 0
num = 6
#while(row < num):
print('7.')
row = 0
num = 6
#while (row < num):
print('8.')
row = 0
num = 6
#while (row <num):
I am expecting to match those expectation results:
1.
xxxxx
xxxx
xxx
xx
x
2.
x
xx
xxx
xxxx
xxxxx
3.
xoooo
xxooo
xxxoo
xxxxo
xxxxx
4.
x
xx
xxx
xxxx
xxxxx
5.
xxxxxxxxx
xxxxxxx
xxxxx
xxx
x
6.
x
x
x
x
x
7.
xxxxx
x x
x x
x x
xxxxx
8.
x_x_x
_x_x_
x_x_x
_x_x_
x_x_x
Aucun commentaire:
Enregistrer un commentaire