Answer the question
In order to leave comments, you need to log in
How to format text correctly?
Hello!
There is a string
We need to make two variables a1 , a2 - And put minutes and seconds from the string into each of them stroka a1 = 1 | (minutes) a2 = 10 | (seconds)
How can this be done?
stroka = 'Время до отключения 1 минута 10 секунд'
Answer the question
In order to leave comments, you need to log in
If your string always has this format Time to Shutdown X minutes Y seconds , then one option is to split it into individual words using the split() method, and then select the necessary values. If necessary, convert them to a number.
stroka = 'Время до отключения 1 минута 10 секунд'
stroka_list = stroka.split() #получим ['Время', 'до', 'отключения', '1', 'минута', '10', 'секунд']
a1 = int(stroka_list[3])
a2 = int(stroka_list[5])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question