Giter Site home page Giter Site logo

karanpratapsingh / learn-go Goto Github PK

View Code? Open in Web Editor NEW
821.0 821.0 86.0 448 KB

Master the fundamentals and advanced features of the Go programming language

Home Page: https://leanpub.com/go

License: Other

Go 100.00%
course go golang tech tutorial

learn-go's People

Contributors

ajejoseph22 avatar erhuabushuo avatar karanpratapsingh avatar onnd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learn-go's Issues

String Formatting example on percentages has error

Problem

In the String Formatting section, the example on percentages is wrong.
It says

...
percent := (3/5) * 100
fmt.Printf("%f", percent)
...

and outputs the result as

$ go run main.go
58.181818

This is wrong for 2 reasons.

  1. 3/5 returns an integer 0 and go would complain about the type and formatting discrepancy (%!f(int=0)).
  2. Even if it were to be written as 3.0/5 (to have the value of percent be a float), that value would be 60.000000, not 58.181818
    See playground here

Suggested solution

For clarity, I suggest we use another example to illustrate this. See below

...
percent := (7.0 / 9) * 100
fmt.Printf("%f", percent)
...
$ go run main.go
77.777778 

and subsequently...

...
percent := (7.0 / 9) * 100
fmt.Printf("%.2f %%", percent)
...
$ go run main.go
77.78 %

See playground here

Links:

License ?

Could you put a license on your great work ?

Small typo in slices chapter

Hi there,

thanks for this guide.
I found a small mistake which could be misleading as it shows wrong usage of the slice. You are showing this code snippet

func main() {
	a := [5]int{20, 15, 5, 30, 25}

	s := a[1:4]

	// Output: Array: [20 15 5 30 25], Length: 5, Capacity: 5
	fmt.Printf("Array: %v, Length: %d, Capacity: %d\n", a, len(a), cap(a))

	// Output: Slice [15 5], Length: 3, Capacity: 4
	fmt.Printf("Slice: %v, Length: %d, Capacity: %d", s, len(s), cap(s))
}

But the actual output of the slice is

// Output: Slice [15 5 30], Length: 3, Capacity: 4
                       ^^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.