text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
probability and that's what | 373.36 | 3.679 |
random.choice does it takes in a list | 374.4 | 4.639 |
and it returns to one of those values | 377.039 | 4.321 |
randomly with equal probability because | 379.039 | 4 |
i've passed in two items i've got a 50 | 381.36 | 4.08 |
50 chance if i passed in three items | 383.039 | 4.801 |
it'd be a 33 chance for each of those | 385.44 | 4.479 |
items and so forth python does the math | 387.84 | 4.24 |
for you but i want to store the value of | 389.919 | 3.601 |
this in a variable so let's define a | 392.08 | 4 |
variable called coin equals whatever the | 393.52 | 4.72 |
return value is so this is indeed like | 396.08 | 3.92 |
flipping a coin i'm going to store in a | 398.24 | 4.32 |
variable called coin whatever that value | 400 | 4.319 |
is heads or tails and now just so i can | 402.56 | 3.6 |
see what's going on let's go ahead and | 404.319 | 4.88 |
print out the value of that string coin | 406.16 | 4.4 |
all right let me go ahead now and run | 409.199 | 3.201 |
this program in my terminal window | 410.56 | 5.28 |
python of generate dot pi enter and it | 412.4 | 5.04 |
looks like the first coin toss was the | 415.84 | 4.479 |
heads let's go ahead and run it again | 417.44 | 4.56 |
and it looks like it was heads again | 420.319 | 3.041 |
maybe you want to chime into the chat | 422 | 3.039 |
here if i run it a third time what's it | 423.36 | 3.36 |
going to be this time if you want to | 425.039 | 4.72 |
type your thoughts in the chat | 426.72 | 4.8 |
you might think there's a bug here but | 429.759 | 4.56 |
this is probability in action if i go | 431.52 | 5.04 |
ahead and hit enter a third time there | 434.319 | 4.641 |
it's actually now tails and again tails | 436.56 | 4.4 |
and again tails and again tails and | 438.96 | 4.639 |
again tails and again heads now if we | 440.96 | 4.56 |
did this an infinite number of times it | 443.599 | 4.241 |
would indeed work out to be 50 50. if we | 445.52 | 4.56 |
only do it a few times it might not work | 447.84 | 3.84 |
out as cleanly but that's how | 450.08 | 3.679 |
probabilities indeed work all right so | 451.68 | 4.48 |
i've got that now working could i have | 453.759 | 3.761 |
implemented this in a different way well | 456.16 | 3.039 |
let me show you an alternative to | 457.52 | 4.799 |
actually using the import keyword alone | 459.199 | 5.44 |
and let me introduce the keyword from in | 462.319 | 5.361 |
python so from is a keyword in python | 464.639 | 4.96 |
that you can use when importing | 467.68 | 4.4 |
functions from a module but it allows | 469.599 | 4.401 |
you to be a little more specific than | 472.08 | 4.08 |
import alone so if i go back to my code | 474 | 3.759 |
here it's worth noting that what | 476.16 | 4.24 |
technically i'm doing here by importing | 477.759 | 4.88 |
random is i'm technically importing | 480.4 | 4.88 |
everything that's in that module so not | 482.639 | 5.441 |
just the function called random.choice | 485.28 | 4.88 |
but a few other functions as well so | 488.08 | 3.519 |
instead of using this line of code at | 490.16 | 3.439 |
the top of my file import random which | 491.599 | 3.841 |
will technically give me access to all | 493.599 | 4.401 |
of the contents they're in a downside of | 495.44 | 5.24 |
that is that i have to type in | 498 | 4.639 |
random.choicerandom.this random.that | 500.68 | 4.12 |
because all of the functions i'm calling | 502.639 | 4.161 |
have to be associated with the scope of | 504.8 | 4 |
that module well suppose that i just | 506.8 | 3.839 |
want to call the function as its name | 508.8 | 3.919 |
choice i can do that as well let me | 510.639 | 4.801 |
replace this first line here with from | 512.719 | 5.841 |
random import choice and what this does | 515.44 | 5.519 |
effectively is it loads the function's | 518.56 | 5.44 |
name choice into my current namespace | 520.959 | 5.521 |
into the scope of the file i'm working | 524 | 4.64 |
in what that means is that i now no | 526.48 | 4.56 |
longer have to specify which choice | 528.64 | 4.72 |
function i mean i can just say choice | 531.04 | 4.32 |
and so it loads it into the local | 533.36 | 3.599 |
namespace that is into my local | 535.36 | 4.08 |
vocabulary if you will so i can just now | 536.959 | 6 |
say choice this might be advantageous | 539.44 | 6 |
in what cases do you think when might | 542.959 | 4.88 |
you want to import the name of the | 545.44 | 5.04 |
function explicitly like this as opposed | 547.839 | 4.641 |
to just saying random.choice | 550.48 | 4.24 |
random.choice throughout your code when | 552.48 | 3.919 |
calling a function | 554.72 | 4.08 |
any instincts here for this alternative | 556.399 | 3.521 |
import | 558.8 | 2.64 |
using from | 559.92 | 3.76 |
um hello i'm mohammed ahmar from egypt | 561.44 | 5.28 |
and maybe if we have a variable that | 563.68 | 5.599 |
its name is basically like choice if i | 566.72 | 4.48 |
have a variable called the choice so i | 569.279 | 3.761 |
need to differentiate which trace i | 571.2 | 3.04 |
choose so | 573.04 | 3.6 |
i'm gonna choose random.choice | 574.24 | 4 |
yeah really good instincts by using the | 576.64 | 3.84 |
first approach by just importing random | 578.24 | 3.92 |
you're making sure that all of its | 580.48 | 4.479 |
contents are associated with are scoped | 582.16 | 5.44 |
to the random module so that you can | 584.959 | 4.32 |
have your own choice function you can | 587.6 | 3.679 |
have your own choice variable you can | 589.279 | 4.081 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.