I created a simple function that generates numbers between each word of my message.
Here is an example :
As you can see, the word "message" is being cut. Is there a way to know the numbers of characters left before python will go to the line?
I use Django (that's why I can use python) and the picture you saw is the result fo the code displayed on my web-page.
Here is the python code:
def generate_grid(message):
final_message = []
message_split = message.split(" ")
words = []
for word in message_split:
words.append(list(word))
# if I want to use letter insstead of numbers
upper_case_alphabet = string.ascii_uppercase
lower_case_alphabet = string.ascii_lowercase
for word in words:
final_message.append('<strong>')
for i in range(len(word)):
final_message.append(word[i].upper())
final_message.append('</strong>')
random_number = random.randint(1, 3)
for _ in range(random_number):
random_char = random.randint(0, 9)
final_message.append(str(random_char))
return mark_safe(" ".join(final_message))
Here is the HTML code:
<div class="col-md-4 white nopadding text-center d-flex flex-column align-self-center justify-content-center">
<div class="sub-lead">
{{ "This is an example message" | generate_grid}}
</div>
</div>
(If there is another way to do it, tell me please :) )
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…