Показать сообщение отдельно

  #9  
Старый 20.04.2022, 12:40
Andrinall
Постоянный
Регистрация: 11.07.2019
Сообщений: 702
С нами: 3601315

Репутация: 148


По умолчанию

Цитата:
Сообщение от laiser  

Я поставил тебе симпу за старание и скажу спасибо за помощь.
Но проблемка в том, что мой вопрос в разделе Python, и я не понимаю, почему вы кидаете код для lua.
Хах, мы гении походу.

Python:





Код:
import
random
import
re
import
string

text
=
"[ b][ b][ b]FFF[c][c][c]"
def
randomCode
(
txt
)
:
if
not
txt
or
len
(
txt
)
==
0
:
return
""
find_b
=
len
(
re
.
findall
(
"\[ b\]"
,
txt
)
)
find_c
=
len
(
re
.
findall
(
"\[c\]"
,
txt
)
)
for
i
in
range
(
0
,
find_b
)
:
txt
=
txt
.
replace
(
"[ b]"
,
str
(
random
.
randint
(
0
,
9
)
)
,
1
)
for
i
in
range
(
0
,
find_c
)
:
#upd: я тут случайно 1 вместо 0 поставил, поправил
rand_int
=
random
.
randint
(
1
,
len
(
string
.
ascii_letters
)
)
txt
=
txt
.
replace
(
"[c]"
,
string
.
ascii_letters
[
rand_int
-
1
:
rand_int
]
,
1
)
return
txt
print
(
randomCode
(
text
)
)


В целом тоже работает



Цитата:
Сообщение от Спойлер  


Python:





Код:
import
random
import
re
import
string
import
time
def
randomCode
(
txt
)
:
if
not
txt
or
len
(
txt
)
==
0
:
return
""
find_b
=
len
(
re
.
findall
(
"\[ b\]"
,
txt
)
)
find_c
=
len
(
re
.
findall
(
"\[c\]"
,
txt
)
)
for
i
in
range
(
0
,
find_b
)
:
txt
=
txt
.
replace
(
"[ b]"
,
str
(
random
.
randint
(
0
,
9
)
)
,
1
)
for
i
in
range
(
0
,
find_c
)
:
rand_int
=
random
.
randint
(
1
,
len
(
string
.
ascii_letters
)
)
txt
=
txt
.
replace
(
"[c]"
,
string
.
ascii_letters
[
rand_int
-
1
:
rand_int
]
,
1
)
return
txt

text
=
"[ b][ b][ b]FFF[c][c][c]"
for
i
in
range
(
0
,
24
)
:
print
(
randomCode
(
text
)
)
time
.
sleep
(
1
)


 
Ответить с цитированием