text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
use the same names as all of the | 591.279 | 3.841 |
functions or variables that are stored | 593.36 | 3.52 |
inside of that file without them | 595.12 | 3.68 |
colliding so to speak and this is a good | 596.88 | 4.24 |
thing in older languages it was the case | 598.8 | 4.159 |
that if you imported someone's library | 601.12 | 3.44 |
you better hope that you're not using | 602.959 | 3.921 |
the same functions or variables as they | 604.56 | 3.92 |
are because you might in fact have some | 606.88 | 3.68 |
kind of conflict python and certain | 608.48 | 3.919 |
other languages allow you to scope the | 610.56 | 3.839 |
names of those functions and variables | 612.399 | 3.841 |
to the file or the module that they come | 614.399 | 4 |
from so that's a good thing but honestly | 616.24 | 4.88 |
this is such a short program or | 618.399 | 4.721 |
equivalently maybe i'm using the choice | 621.12 | 4.24 |
function in so many places | 623.12 | 4.12 |
calling | 625.36 | 2.88 |
random.choicerandom.choicerandom.choice | 627.24 | 2.599 |
it's just making my code longer and | 628.24 | 4.08 |
longer and longer marginally so but it's | 629.839 | 4.961 |
just getting ugly and annoying i can | 632.32 | 4.72 |
simply import choice and now tighten up | 634.8 | 4.159 |
my code a little bit so as with so many | 637.04 | 3.6 |
decisions in the past there's not | 638.959 | 3.601 |
necessarily one right approach or | 640.64 | 3.68 |
another it depends but i think for those | 642.56 | 3.76 |
very reasons sometimes it's better to do | 644.32 | 4.32 |
what we did the first time which is only | 646.32 | 4.959 |
import the module so as to retain the | 648.64 | 5.04 |
scope therein well let me propose that | 651.279 | 4.161 |
we transition to another function that | 653.68 | 4.08 |
comes with python's random module and | 655.44 | 4.32 |
that's this here from the documentation | 657.76 | 4.4 |
rand int it's a bit hard to say but it | 659.76 | 4.639 |
implies get back a random int and if you | 662.16 | 4.16 |
read the documentation it's a random end | 664.399 | 4.161 |
that's between a and b | 666.32 | 4.72 |
inclusive so if you were to pass in 1 | 668.56 | 5.04 |
for a and 10 for b you would get back a | 671.04 | 4.88 |
number between 1 and 10 inclusive | 673.6 | 4.32 |
including the 1 and including the 10 | 675.92 | 4.88 |
potentially each with a 10 probability | 677.92 | 4.8 |
so how might i go about using a program | 680.8 | 3.52 |
like this well let me come back to my | 682.72 | 4 |
generate.pi file and why don't we go | 684.32 | 4.32 |
ahead and try generating a random number | 686.72 | 3.28 |
between one and ten you might do this | 688.64 | 2.639 |
frequently in the real world when you | 690 | 2.399 |
just want someone to pick a random | 691.279 | 2.321 |
number you tell them as much and the | 692.399 | 3.281 |
human responds let's get the computer to | 693.6 | 3.919 |
do the same here let me go ahead and | 695.68 | 3.599 |
delete my two lines of code at the | 697.519 | 3.841 |
bottom but keep my import random and | 699.279 | 3.521 |
let's go ahead and define a variable | 701.36 | 3.52 |
this time called number set it equal to | 702.8 | 4.96 |
the return value of random.randint | 704.88 | 4.639 |
and now pass in a | 707.76 | 5.44 |
a value of 1 and b a value of 10 and now | 709.519 | 6.081 |
let's go ahead and print the number i'm | 713.2 | 3.92 |
going to go ahead in my terminal window | 715.6 | 3.6 |
and run python of generate dot pi and | 717.12 | 3.279 |
hit enter | 719.2 | 2.72 |
four | 720.399 | 4 |
python of generate.pi and hit enter | 721.92 | 4.159 |
eight again | 724.399 | 6.081 |
nine again seven again ten again | 726.079 | 6.401 |
two again and we can do this all day | 730.48 | 3.76 |
long and if we add all those up they | 732.48 | 3.76 |
should end up being with ten percent | 734.24 | 4.56 |
probability each now how might you use | 736.24 | 3.839 |
this information well maybe we're | 738.8 | 2.8 |
playing a guessing game or maybe we're | 740.079 | 4.241 |
trying to randomize the behavior of some | 741.6 | 4.799 |
character in the game you can imagine | 744.32 | 4.079 |
using very simple building blocks like | 746.399 | 3.761 |
this just kind of spicing up your | 748.399 | 3.44 |
program by getting it to do things a | 750.16 | 4 |
little less predictably because you're | 751.839 | 4.641 |
choosing these values seemingly randomly | 754.16 | 3.6 |
and you're deferring to python to | 756.48 | 3.039 |
actually do the generation of these | 757.76 | 2.8 |
numbers | 759.519 | 3.041 |
using its own algorithms and its own | 760.56 | 4.079 |
math well what more could we do here let | 762.56 | 3.6 |
me propose that we introduce another | 764.639 | 2.961 |
function that comes from this random | 766.16 | 3.04 |
library yet another that you yourself | 767.6 | 4.239 |
have to don't have to implement shuffle | 769.2 | 4.079 |
if you read the documentation for | 771.839 | 3.761 |
shuffle in the same random module you'll | 773.279 | 4.321 |
see that it takes in a list for instance | 775.6 | 4.32 |
of values and just shuffles them up it | 777.6 | 4.799 |
randomizes them like a deck of cards | 779.92 | 4 |
here you might shuffle them so it's to | 782.399 | 3.521 |
put them into seemingly random order | 783.92 | 4.24 |
well how do i use this based on this | 785.92 | 4.08 |
function's name well let me propose that | 788.16 | 4.16 |
we go back to vs code here and let me go | 790 | 4.56 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.