A
A
aassqqww2021-12-06 13:45:49
random numbers
aassqqww, 2021-12-06 13:45:49

How can I make the bot (in a VK conversation) send a random number (python language) when given a command?

It is necessary that, with a certain command, for example, "number", the bot sends a random number to the conversation chat

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Optimus, 2015-05-29
Pyan @marrk2

Well, what would he see them (dates) works like this https://regex101.com/r/gI6vG8/3 so that he doesn’t understand more than zero, in the date of the year there is always a zero ...

T
tplus, 2015-05-29
@tplus

[1-9]\d{3,}-[1-9]\d{1}-[1-9]\d{1}
About more than zero, too, did not understand. If it is necessary that there is no 0 at the beginning of the GMD, then like this: https://regex101.com/r/kA2jF8/1

D
Denis, 2015-05-29
@prototype_denis

$date = '2016-00-00';
if (strtotime($date) > 0) {   
    // 2016-00-00 => 2015-11-30
    
    if (preg_match('/(0000|00)/', $date)) {
        // 2016-00-01 || 0000-00
    } else {
        // 2016-01-01
    }
} else {
    // 2016-sss-01 || 99999999999999999999999999-01-01
}

$date   = '2015-11-31';

$parts  = explode('-', $date);
if ($isValid = strtotime($date)) {
    $isValid = ($parts === array_map(function($part) {
        return ($part > 0 ? $part : false);
    }, $parts));
}

if ($isValid) {
    // ...
} else {
    // ...
}

N
nnnice, 2017-04-07
@nnnice

To work with regular expressions, use special services that not only "underline" errors, but also help to figure out what is wrong. There are examples in these services as small cheat sheets for beginners, and support for a variety of PLs. The most popular thing is regex101 , of course. Supports PHP, JavaScript, Golang and Python + there is a code generator with support for C#, Java, Ruby, Rust, Perl. RegexPlanet, from Russian you can click Planetcalc. I take links to these and others from here: regular expressions and everything about them are collected in one place. There will be questions - write, I will answer everything and help you understand the services. Good luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question