This course has been updated! We now recommend you take the Basics of Go course.
Transcript from the "Printing Solution" Lesson
>> And the first thing we needed to do was create a file called exercise 2a.go. So I'm going to put that in my code directory here in my repository. Exercise 2a.go. And then the first thing we were asked to do is just replicate the hello world example that we started with from the beginning.
[00:00:20] And because we're starting with a blank slate, this gives us an example of kind of writing a go file from scratch once again. So we'll start with our package main. And then, because we're working with the filmed package, that's the whole point of the exercise, I'm going to go ahead and import the filmed package here, the library, excuse me.
[00:00:41] And then in my main file I am going to choose thumb to print line, so I can have that extra new line at the end of the sentence and I am just going to type hello world. If I save this, open up my terminal And then instead of practice.go, I'm going to say go run, I'm in the second directory, code directory, exercise_2a.go.
[00:01:07] So go run is going to execute that file and I'll see Hello World print to the console. I'm gonna go ahead and comment that guy out and work on the second one. So the second example that we wanted to print out is kind of around the printf functionality.
[00:01:24] And so the sentence we wanted was, hi, my name is Brenna, I've lived in Denver for 4 years, they say the weather is amazing, which is true. So I'm actually just gonna copy this guy so I don't have to retype it. And then go back to my exercise 2a.go file.
[00:01:42] So I know I want printf because I'm going to be interpolating some variables here. And then the string so far it looks like this. As I'm kind of looking at it, I'm gonna leave it add my variables at the end, and then circle back but the first one is going to be a string of Brenna.
[00:02:00] And I'll change this to a percent s. The next is I've lived in Denver for four years. So we can make this percent d for an integer and that will be four. And then the third is the true or false here, and so that is percent t for true.
[00:02:27] Save that, rerun my program, and you see, hi, my name is Brenna, I've lived in Denver for four years, they say the weather's amazing, which is true. There is no new line here, but that's okay, we could add that if we'd like.