1, diamond print
# - * - Coding: UTF- . 8 - * - # Version:. To python3 . 7 '' ' @ File : print_graphics @ author: zhangyangyang @ Create: 2020 / . 3 / 22 is @ the remark: ' '' # print diamond # version1: Derivation the number of spaces and ' * ' relationship between the number of spaces + "*" = n (length) n- = . 7 E = n- // 2 for I in Range (-e, + E . 1 ): defines the number of spaces #: [- . 3 , . 3 ] #if I <0: # I = -I #Print ( ' {} {} ' .format ( ' ' * I, (n-- 2 * I) * ' * ' )) Print ( ' {} {} ' .format ( ' ' * ABS (I), (n-- 2 * ABS (I)) * ' * ' )) #abs (): absolute value
execution results:
*
***
*****
*******
*****
** *
*
# Version2: print centering n- =. 7 E = n-2 // for I in Range (-e, + E. 1 ): Print ( " {:}} ^ { " .format ( ' * ' * (n-- 2 * ABS (i)), n)) The results: * *** ***** ******* ***** *** *
2, printing of a triangle
# Vsrsion1 n- =. 7 E = n-2 // for I in Range (-e, + E. 1 ): # Print ( '' * (E - ABS (I)) + '{}'. The format ( '*' * (2 * ABS (I) +. 1))) Print ( ' : {}} ^ { ' .format ( ' * ' * (2 * ABS (I) +. 1 ), n-)) The results: **** *** ***** *** * *** ***** *******
# Version2 n- =. 7 E = n-2 // for I in Range (-e, N- E): Print ( ' {} {} ' .format ( ' ' * (E - ABS (I)), ' * ' * (2 * ABS (I) +. 1 ))) The results: ******* ***** *** * *** ***** *******
3, Lightning Print
# Print Lightning n- =. 7 E = n-2 // X = n-- E for I in Range (- E, X): IF I < 0: Print ( ' ' * -i + (X + I) * ' * ' ) elif I> 0: Print ( ' ' * E + (X - I) * ' * ' ) the else : Print ( ' * ' * n-) The results: * ** *** ******* *** ** *