(1).
for i in range(5+1):
for j in range(i+1):
print('*',end='')
print()
*
**
***
****
*****
******
for i in range(5+1):
print("i=",i,end=' ')
for j in range(i+1):
print("j=",j,'*',end=' ')
print()
i= 0 j= 0 *
i= 1 j= 0 * j= 1 *
i= 2 j= 0 * j= 1 * j= 2 *
i= 3 j= 0 * j= 1 * j= 2 * j= 3 *
i= 4 j= 0 * j= 1 * j= 2 * j= 3 * j= 4 *
i= 5 j= 0 * j= 1 * j= 2 * j= 3 * j= 4 * j= 5 *
(2).
for i in range(-4,4+1):
print(abs(i)*' ',end='') #abs(i)*' ' 有空格
for j in range(1,5-abs(i)+1):
print(' *',end='')
print()
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
for i in range(-4,4+1):
print(abs(i)*'',end='') #abs(i)*'' 沒有空格
for j in range(1,5-abs(i)+1):
print(' *',end='')
print()
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
(3).
for i in range(1,5+1):
for j in range(1,i+1):
print(i,end='')
print()
1
22
333
4444
55555
(4).
for i in range(-4,4+1): for j in range(-4,4+1):
if(abs(i)>abs(j)):
print(abs(i)+1,end='')
else:
print(abs(j)+1,end='')
print()
544444445
543333345
543222345
543212345
543222345
543333345
544444445
555555555
(5).
for i in range(5):
for j in range(i+1):
print(chr(65+i),end='')
print()
A
BB
CCC
DDDD
EEEEE
(6).
for i in range(0,5):
print('*')
print()
*
*
*
*
*
for i in range(0,5):
print('*',end='')
print()
*****
for i in range(1,5+1):
print(i)
print()
1
2
3
4
5
for i in range(1,5+1):
print(i,end='')
print()
12345
for i in range(0,5):
print(chr(65+i))
print()
A
B
C
D
E
for i in range(0,5):
print(chr(65+i),end='')
print()
ABCDE
(7).
for i in range(1,4+1):
for j in range(1,3+1):
for k in range(i):
print(j*'*'+(3-j)*' ',end='')
print()
*
**
***
* *
** **
******
* * *
** ** **
*********
* * * *
** ** ** **
************
(8).
for i in range(1,8):
print((8-i)*' '+'*'+(((i-1)*2)-1)*' '+(i>1)*'*')
print((i+1)*'* ')
*
* *
* *
* *
* *
* *
* *
* * * * * * * *
(9-0).
for i in range(-4,4+1):
for j in range(-4,4+1):
if (abs(i)>abs(j)-1):
print('*',end='')
else:
print(' ',end='')
print()
*********
*******
*****
***
*
***
*****
*******
*********
(9-1).
for i in range(-4,4+1):
for j in range(-4,4+1):
if (abs(i)<abs(j)+1):
print('*',end='')
else:
print(' ',end='' )
print()
* *
** **
*** ***
**** ****
*********
**** ****
*** ***
** **
* *
(9-2).
for i in range(-4,4+1):
for j in range(-4,4+1):
if ((abs(i)+abs(j))<4):
print(' ',end='')
else:
print('*',end='' )
print()
*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********
(10).
for i in range(1,9+1):
for j in range(-9,9+1):
if (j==0) or (i>9-abs(j)):
print(' ',end='')
else:
print('*',end='')
print()
******** ********
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
(11).
for i in range(1,5+1):
for j in range(1,2+1):
print((5-i)*' ',end='')
for k in range(1,i+1):
print('* ',end='')
print((5-i)*' ',end='')
print()
print()
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
(12).
for i in range(1,5+1):
for j in range(6-i,0,-1):
print(chr(i+64),end='')
print()
BBBB
CCC
DD
E
(13).
x=0
for i in range(1,5+1):
for j in range(i):
x=1-x
print(x,end='')
print()
01
010
1010
10101
(14).
for i in range(5):
for j in range(5):
if (i==j):
print(0,end='')
else:
print(i+1,end='')
print()
01111
20222
33033
44404
55550
(15).
for i in range(1,5+1):
for j in range(-4,4+1):
if (i >= abs(j)+1):
print(i-abs(j),end='')
else:
print(' ',end='')
print()
121
12321
1234321
123454321
(16).
for i in range(1,5+1):
for j in range(1,5+1):
if (i +j>=6):
print(6-i,end='')
else:
print(' ',end='')
print()
5
44
333
2222
11111
(17).
x=1
for i in range(1,5+1):
for j in range(1,i+1):
print('%3d' %(x),end='')
x=x+1
print()
2 3
4 5 6
7 8 9 10
11 12 13 14 15
(18).
for i in range(1,6+1):
for j in range(-5,5+1):
if(i<abs(j)+2):
print(chr(65+(5-abs(j))),end='')
else:
print(' ',end='')
print()
ABCDEFEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
(19).
str="SCHOOL"
for i in range(6):
print(str[0:i+1])
print('\n')
S
SC
SCH
SCHO
SCHOO
SCHOOL
(20).
for i in range(-4,4+1):
for j in range(-4,4+1):
if (abs(i)==abs(j)):
print(chr(97+abs(i)),end='')
else:
print(' ',end='' )
print()
e e
d d
c c
b b
a
b b
c c
d d
e e
沒有留言:
張貼留言