lundi 19 juin 2023

Draw pattern in python depending on direction and length of number input

I try to write a function print_histogram(n, direction='⇑', colour='blue') takes in

- a positive integer (possibly 0) as first argument;

- a character that represents one of 4 possible irections as second argument;

- the string 'blue' or 'red' as third argument.

Both second and third arguments have default values

I want to use the digits of the first argument to print out a histogram that "grows" in the direction given by the second argument, the square that marks the start of the first bar being of colour given by the third argument. What is printed out is a rectangle with a checkered pattern, the white squares "outside" the histogram "hiding" the pattern.

Below is the example of my desired input and output

for ex : print_histogram(1003290, direction='⇑', colour='blue') or print_histogram(1003290)

enter image description here

print_histogram(1003290, '⇒')

enter image description here

print_histogram(1003290, colour='red')
enter image description here

print_histogram(1003290, '⇓', 'red')
enter image description here

The code points of the Unicode characters are in base 16: 21d0, 21d1, 21d2, 21d3, 1f7e6, 1f7e5 and 2b1c. Could you help me with this ? I am confused how to make the connection between the direction and also alternating the check board

Aucun commentaire:

Enregistrer un commentaire