
you made it part 2 congratulations so so in this tutorial we’re just gonna be
in this tutorial we’re just gonna be
in this tutorial we’re just gonna be kind of taking it a little closer look
kind of taking it a little closer look
kind of taking it a little closer look at the the kind of intricacies that are
at the the kind of intricacies that are
at the the kind of intricacies that are going on here and then cover a few more
going on here and then cover a few more
going on here and then cover a few more things that we didn’t talk about in the
things that we didn’t talk about in the
things that we didn’t talk about in the in the previous tutorial so again I’m
in the previous tutorial so again I’m
in the previous tutorial so again I’m gonna start with a clean slate just
gonna start with a clean slate just
gonna start with a clean slate just because we have a lot of code anyway so
because we have a lot of code anyway so
because we have a lot of code anyway so it’s not a big deal
it’s not a big deal
it’s not a big deal but everything is pretty much gonna
but everything is pretty much gonna
but everything is pretty much gonna start with package main and then we get
start with package main and then we get
start with package main and then we get to the imports now in the case of the
to the imports now in the case of the
to the imports now in the case of the previous tutorial we just had format but
previous tutorial we just had format but
previous tutorial we just had format but if you wanted in most cases you’re not
if you wanted in most cases you’re not
if you wanted in most cases you’re not gonna write a program that has a single
gonna write a program that has a single
gonna write a program that has a single import that’s just not likely so you
import that’s just not likely so you
import that’s just not likely so you could you could import other things this
could you could import other things this
could you could import other things this way so math is another package that’s
way so math is another package that’s
way so math is another package that’s part of your standard library but this
part of your standard library but this
part of your standard library but this is not really the method that you should
is not really the method that you should
is not really the method that you should use so instead what you’re gonna do is
use so instead what you’re gonna do is
use so instead what you’re gonna do is you’re gonna import and then you’re
you’re gonna import and then you’re
you’re gonna import and then you’re going to import in parentheses and then
going to import in parentheses and then
going to import in parentheses and then you’ll just kind of add everything in
you’ll just kind of add everything in
you’ll just kind of add everything in here that you’re gonna wind up using so
here that you’re gonna wind up using so
here that you’re gonna wind up using so math the other thing I think go has go
math the other thing I think go has go
math the other thing I think go has go does have like a Styles document but I
does have like a Styles document but I
does have like a Styles document but I doesn’t appear to me that the go
doesn’t appear to me that the go
doesn’t appear to me that the go community is as pushy about styles
community is as pushy about styles
community is as pushy about styles obviously there’s some things like tabs
obviously there’s some things like tabs
obviously there’s some things like tabs and stuff like that they want you to do
and stuff like that they want you to do
and stuff like that they want you to do and like indenting and stuff like that
and like indenting and stuff like that
and like indenting and stuff like that that that something like sublime is just
that that something like sublime is just
that that something like sublime is just gonna do for you but anyways I just
gonna do for you but anyways I just
gonna do for you but anyways I just thought about that as I tabbed over a
thought about that as I tabbed over a
thought about that as I tabbed over a math to be in line with format
math to be in line with format
math to be in line with format there are rules somewhere I’ll link to
there are rules somewhere I’ll link to
there are rules somewhere I’ll link to them at some point in the in the text
them at some point in the in the text
them at some point in the in the text base tutorial but you could probably
base tutorial but you could probably
base tutorial but you could probably find them as well but if things like how
find them as well but if things like how
find them as well but if things like how many spaces like you should probably
many spaces like you should probably
many spaces like you should probably have like an empty line between packages
have like an empty line between packages
have like an empty line between packages and import and then at least like one
and import and then at least like one
and import and then at least like one white space between functions stuff like
white space between functions stuff like
white space between functions stuff like that I kind of like to have two white
that I kind of like to have two white
that I kind of like to have two white spaces I honestly don’t know what the
spaces I honestly don’t know what the
spaces I honestly don’t know what the rule is and I’m not really sure the
rule is and I’m not really sure the
rule is and I’m not really sure the community has has fully decided on that
community has has fully decided on that
community has has fully decided on that but anyway sorry if I if I make somebody
but anyway sorry if I if I make somebody
but anyway sorry if I if I make somebody angry here anyways that’s how you would
angry here anyways that’s how you would
angry here anyways that’s how you would import multiple packages now the next
import multiple packages now the next
import multiple packages now the next thing is let’s do let’s go ahead and use
thing is let’s do let’s go ahead and use
thing is let’s do let’s go ahead and use something from math because as you saw
something from math because as you saw
something from math because as you saw before we
before we
before we we did well let’s go ahead and just funk
and so so before we have format dot
and so so before we have format dot print L and and then we printed
print L and and then we printed
print L and and then we printed something right and we’re gonna go ahead
something right and we’re gonna go ahead
something right and we’re gonna go ahead and continue doing that but we can also
and continue doing that but we can also
and continue doing that but we can also we could say something like let’s do the
we could say something like let’s do the
we could say something like let’s do the square root of four is and then comma
square root of four is and then comma
square root of four is and then comma math dot SQ RT and then floor will pass
math dot SQ RT and then floor will pass
math dot SQ RT and then floor will pass that through now something you might
that through now something you might
that through now something you might notice is the usage of casings so it’s
notice is the usage of casings so it’s
notice is the usage of casings so it’s not by mistake so capital peak and
not by mistake so capital peak and
not by mistake so capital peak and capital S here in go the cat if the
capital S here in go the cat if the
capital S here in go the cat if the first letter is capitalized that
first letter is capitalized that
first letter is capitalized that function will be exported by go and or
function will be exported by go and or
function will be exported by go and or that element for that matter so if you
that element for that matter so if you
that element for that matter so if you do not capitalize that first letter it’s
do not capitalize that first letter it’s
do not capitalize that first letter it’s considered to be kind of like an
considered to be kind of like an
considered to be kind of like an internal thing whereas so like if you’re
internal thing whereas so like if you’re
internal thing whereas so like if you’re using a package you can rest assured
using a package you can rest assured
using a package you can rest assured that all the functions that you’re using
that all the functions that you’re using
that all the functions that you’re using from that package will start with the
from that package will start with the
from that package will start with the capital letter if they didn’t I don’t I
capital letter if they didn’t I don’t I
capital letter if they didn’t I don’t I just that can’t exist so so so so just
just that can’t exist so so so so just
just that can’t exist so so so so just just know that and get used to using
just know that and get used to using
just know that and get used to using that kind of capital letter there so
that kind of capital letter there so
that kind of capital letter there so that’s another thing to think about now
that’s another thing to think about now
that’s another thing to think about now the next thing is like if you’re coming
the next thing is like if you’re coming
the next thing is like if you’re coming from Python this main function like we
from Python this main function like we
from Python this main function like we never caught you know we never said pay
never caught you know we never said pay
never caught you know we never said pay main run what happens you go is the main
main run what happens you go is the main
main run what happens you go is the main function is considered your your main
function is considered your your main
function is considered your your main loop so to speak it will always run it’s
loop so to speak it will always run it’s
loop so to speak it will always run it’s like the init method in a class or
like the init method in a class or
like the init method in a class or something like that in Python language
something like that in Python language
something like that in Python language it’s just always gonna run so whatever
it’s just always gonna run so whatever
it’s just always gonna run so whatever you pass through here will run so for
you pass through here will run so for
you pass through here will run so for example if you did you know func foo and
example if you did you know func foo and
example if you did you know func foo and then you know I don’t know put some
then you know I don’t know put some
then you know I don’t know put some thought we gonna put this in here so
thought we gonna put this in here so
thought we gonna put this in here so we’ll just cut paste and we save that if
we’ll just cut paste and we save that if
we’ll just cut paste and we save that if we actually go to run that I’ll bring
we actually go to run that I’ll bring
we actually go to run that I’ll bring over the command line here go run go tot
over the command line here go run go tot
over the command line here go run go tot go we see nothing actually happens
go we see nothing actually happens
go we see nothing actually happens because the only thing that it’s not
because the only thing that it’s not
because the only thing that it’s not like all your functions run it’s just
like all your functions run it’s just
like all your functions run it’s just the main function will run so now we
the main function will run so now we
the main function will run so now we could pass
could pass
could pass phoo in here and run that again and then
phoo in here and run that again and then
phoo in here and run that again and then now you see yes the square root of 4 is
now you see yes the square root of 4 is
now you see yes the square root of 4 is 2 okay so so there’s that now also
2 okay so so there’s that now also
2 okay so so there’s that now also sometimes you’ll have like packages
sometimes you’ll have like packages
sometimes you’ll have like packages inside of packages also let me fix this
inside of packages also let me fix this
inside of packages also let me fix this so so in this case you’ve got you know
so so in this case you’ve got you know
so so in this case you’ve got you know format math and then like let’s say for
format math and then like let’s say for
format math and then like let’s say for example we wanted to import so like
example we wanted to import so like
example we wanted to import so like square root is sum is is is a function
square root is sum is is is a function
square root is sum is is is a function that’s just right in the math package
that’s just right in the math package
that’s just right in the math package but then there’s also kind of sub
but then there’s also kind of sub
but then there’s also kind of sub packages in math one of those is random
packages in math one of those is random
packages in math one of those is random so RND so if so if you like in Python it
so RND so if so if you like in Python it
so RND so if so if you like in Python it would be a dot notation but in the for
would be a dot notation but in the for
would be a dot notation but in the for the imports it’s going to be slash and
the imports it’s going to be slash and
the imports it’s going to be slash and you wouldn’t be able to say like down
you wouldn’t be able to say like down
you wouldn’t be able to say like down here math /r and slash whatever you plan
here math /r and slash whatever you plan
here math /r and slash whatever you plan to use or dot whatever you’re planning
to use or dot whatever you’re planning
to use or dot whatever you’re planning to use and you also couldn’t do math dot
to use and you also couldn’t do math dot
to use and you also couldn’t do math dot R and like that that’s not gonna work
R and like that that’s not gonna work
R and like that that’s not gonna work you have to actually you’ll have to
you have to actually you’ll have to
you have to actually you’ll have to import the packages and full up here all
import the packages and full up here all
import the packages and full up here all the way to the point where you’re going
the way to the point where you’re going
the way to the point where you’re going to use that actual function so so math
to use that actual function so so math
to use that actual function so so math /r and and then now what we can actually
/r and and then now what we can actually
/r and and then now what we can actually do is is let’s go ahead and I’m gonna
do is is let’s go ahead and I’m gonna
do is is let’s go ahead and I’m gonna get rid of the Foo function we don’t
get rid of the Foo function we don’t
get rid of the Foo function we don’t really need that anymore and then I’m
really need that anymore and then I’m
really need that anymore and then I’m just gonna say format dot capital P
just gonna say format dot capital P
just gonna say format dot capital P print line and then what we can say is
print line and then what we can say is
print line and then what we can say is something like a number from 1 to 100
something like a number from 1 to 100
something like a number from 1 to 100 and then we’ll just say Rand dot capital
and then we’ll just say Rand dot capital
and then we’ll just say Rand dot capital I and T N and then 100 so this will just
I and T N and then 100 so this will just
I and T N and then 100 so this will just generate a random number up to a hundred
generate a random number up to a hundred
generate a random number up to a hundred and come over here and oh we didn’t save
and come over here and oh we didn’t save
and come over here and oh we didn’t save it we’re gonna say that first try again
it we’re gonna say that first try again
it we’re gonna say that first try again there we go number one to 100 is 81 and
there we go number one to 100 is 81 and
there we go number one to 100 is 81 and in fact that might actually be 0 to 100
in fact that might actually be 0 to 100
in fact that might actually be 0 to 100 I’ll have to confirm that but that’s
I’ll have to confirm that but that’s
I’ll have to confirm that but that’s most likely actually or maybe even
most likely actually or maybe even
most likely actually or maybe even better put it’s probably 0 to 99 I’m not
better put it’s probably 0 to 99 I’m not
better put it’s probably 0 to 99 I’m not 100% on that one so I’m even comment
100% on that one so I’m even comment
100% on that one so I’m even comment below if you actually know the answer to
below if you actually know the answer to
below if you actually know the answer to that the intend we could look it up as
that the intend we could look it up as
that the intend we could look it up as well and figure out exactly how that’s
well and figure out exactly how that’s
well and figure out exactly how that’s working and in fact let’s just show an
working and in fact let’s just show an
working and in fact let’s just show an example of that while we’re here so if
example of that while we’re here so if
example of that while we’re here so if you want to know more about a function
you want to know more about a function
you want to know more about a function or package for that matter or anything
or package for that matter or anything
or package for that matter or anything you want to know more about you can use
you want to know more about you can use
you want to know more about you can use go doc so for example we could say go
go doc so for example we could say go
go doc so for example we could say go doc from the format package we want to
doc from the format package we want to
doc from the format package we want to learn more about a print line so print a
learn more about a print line so print a
learn more about a print line so print a line well hit enter there and then this
line well hit enter there and then this
line well hit enter there and then this just kind of tells us a little bit more
just kind of tells us a little bit more
just kind of tells us a little bit more about what we’re doing so it tells us ok
about what we’re doing so it tells us ok
about what we’re doing so it tells us ok here’s the function it takes a interface
here’s the function it takes a interface
here’s the function it takes a interface and then you’ve got you know just all
and then you’ve got you know just all
and then you’ve got you know just all your information basically and it tells
your information basically and it tells
your information basically and it tells you a little bit more about how it
you a little bit more about how it
you a little bit more about how it actually works what it returns all of
actually works what it returns all of
actually works what it returns all of that so for that matter we could also do
that so for that matter we could also do
that so for that matter we could also do the same thing with int n I’m not
the same thing with int n I’m not
the same thing with int n I’m not positive this will be good enough for us
positive this will be good enough for us
positive this will be good enough for us but we’ll see we’ll see what it says
but we’ll see we’ll see what it says
but we’ll see we’ll see what it says go doc what was it math slash brand and
go doc what was it math slash brand and
go doc what was it math slash brand and then int and so basically into n into n
then int and so basically into n into n
then int and so basically into n into n returns yeah do you ran a number and 0
returns yeah do you ran a number and 0
returns yeah do you ran a number and 0 and
so I’m gonna assume that 0 to the number
so I’m gonna assume that 0 to the number so I don’t think you would ever actually
so I don’t think you would ever actually
so I don’t think you would ever actually be a 100 but anyway someone like I said
be a 100 but anyway someone like I said
be a 100 but anyway someone like I said feel free to correct me if I’m wrong the
feel free to correct me if I’m wrong the
feel free to correct me if I’m wrong the other thing to keep in mind with go it’s
other thing to keep in mind with go it’s
other thing to keep in mind with go it’s more true or it’s a more honest Rand
more true or it’s a more honest Rand
more true or it’s a more honest Rand random than pythons random so if you if
random than pythons random so if you if
random than pythons random so if you if we run this again I don’t even remember
we run this again I don’t even remember
we run this again I don’t even remember what the first one was oh it was 81 so
what the first one was oh it was 81 so
what the first one was oh it was 81 so please keep running this and it’s always
please keep running this and it’s always
please keep running this and it’s always going to be 81 if if you don’t want it
going to be 81 if if you don’t want it
going to be 81 if if you don’t want it to be 81 you have to you have to specify
to be 81 you have to you have to specify
to be 81 you have to you have to specify the the random seed and all of that in
the the random seed and all of that in
the the random seed and all of that in Python you don’t necessarily need to do
Python you don’t necessarily need to do
Python you don’t necessarily need to do that but if you don’t do that in Python
that but if you don’t do that in Python
that but if you don’t do that in Python you will notice patterns in in the in
you will notice patterns in in the in
you will notice patterns in in the in the output of Python but if you don’t
the output of Python but if you don’t
the output of Python but if you don’t pay close attention to the output of
pay close attention to the output of
pay close attention to the output of random you might be under the impression
random you might be under the impression
random you might be under the impression that yes it’s pseudo-random but it’s
that yes it’s pseudo-random but it’s
that yes it’s pseudo-random but it’s still good enough random for doing a lot
still good enough random for doing a lot
still good enough random for doing a lot of things but actually even in Python
of things but actually even in Python
of things but actually even in Python it’s really not I’m sure a lot of other
it’s really not I’m sure a lot of other
it’s really not I’m sure a lot of other languages are the same if they don’t
languages are the same if they don’t
languages are the same if they don’t make you do anything with the seed but
make you do anything with the seed but
make you do anything with the seed but go is going to be truly honest with you
go is going to be truly honest with you
go is going to be truly honest with you and say ok it’s always 81 until you
and say ok it’s always 81 until you
and say ok it’s always 81 until you change the seed so so that’s pretty
change the seed so so that’s pretty
change the seed so so that’s pretty useful anyway so so that’s all for now
useful anyway so so that’s all for now
useful anyway so so that’s all for now just a few more things I wanted to cover
just a few more things I wanted to cover
just a few more things I wanted to cover before we actually start getting into
before we actually start getting into
before we actually start getting into the true grunt work of what’s going on
the true grunt work of what’s going on
the true grunt work of what’s going on in go if you have questions comments
in go if you have questions comments
in go if you have questions comments concerns whatever feel free to leave
concerns whatever feel free to leave
concerns whatever feel free to leave them below otherwise I will see you in
them below otherwise I will see you in
them below otherwise I will see you in the next tutorial
”
Be First to Comment