Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chinese translation for 08-numbers-and-strings (numbers part) #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
// 当一个整数和一个浮点数一起使用时
// 在一个表达式中,其结果总是变成一个浮点数
fmt.Println(8 * -4.0) // -32.0 not -32

// 两个整数值的结果是一个整数值
fmt.Println(-4 / 2)

// 取余运算符
// 它只能用于整数
fmt.Println(5 % 2)
// fmt.Println(5.0 % 2) // 错误的

// 加法运算符
fmt.Println(1 + 2.5)
fmt.Println(2 - 3)

// 负数运算符
fmt.Println(-(-2))
fmt.Println(- -2) // 这也可以
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
var (
myAge = 30
yourAge = 35
average float64
)

average = float64(myAge+yourAge) / 2

fmt.Println(average)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
ratio := 1.0 / 10.0

// 经过10次操作后
// 不准确的地方很明显
//
// 不过,现在不要介意这个循环的语法
// 我将在事后解释
for range [...]int{10: 0} {
ratio += 1.0 / 10.0
}

fmt.Printf("%.60f", ratio)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
// Go编译器将这些数字视为整数,
// 因为整数值中没有小数部分
// 所以, 结果是1, 而不是1.5

// 所以, 这里的ratio变量是一个int变量
// 这是因为, 3除以2的结果是一个整数

ratio := 3 / 2

fmt.Printf("%d", ratio)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
// 当你在计算中使用一个浮点数和一个整数时
// 结果总是一个浮点数。

ratio := 3.0 / 2

// OR:
// ratio = 3 / 2.0

// OR - 如果3在一个int变量里:
// n := 3
// ratio = float64(n) / 2

fmt.Printf("%f", ratio)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
fmt.Println("sum :", 3+2) // sum - int
fmt.Println("sum :", 2+3.5) // sum - float64
fmt.Println("dif :", 3-1) // difference - int
fmt.Println("dif :", 3-0.5) // difference - float64
fmt.Println("prod:", 4*5) // product - int
fmt.Println("prod:", 5*2.5) // product - float64
fmt.Println("quot:", 8/2) // quotient - int
fmt.Println("quot:", 8/1.5) // quotient - float64

// 余数仅适用于整数
fmt.Println("rem :", 8%3)
// fmt.Println("rem:", 8.0%3) // error

// 你可以这样做
// 因为浮点数的小数部分为零
f := 8.0
fmt.Println("rem :", int(f)%3)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
// 这个ratio的值是什么?
// 3 / 2 = 1.5?
var ratio float64 = 3 / 2
fmt.Println(ratio)

// 说明
// 上述表达式等于这个
ratio = float64(int(3) / int(2))
fmt.Println(ratio)

// 如何修复?
//
// 记住,当其中一个值是浮点数的时候
// 结果就会变成浮点数
ratio = float64(3) / 2
fmt.Println(ratio)

// or
ratio = 3.0 / 2
fmt.Println(ratio)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
fmt.Println(
2+2*4/2,
2+((2*4)/2), // 同上
)

fmt.Println(
1+4-2,
(1+4)-2, // 同上
)

fmt.Println(
(2+2)*4/2,
(2+2)*(4/2), // 同上
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
n, m := 1, 5

fmt.Println(2 + 1*m/n)
fmt.Println(2 + ((1 * m) / n)) // 同上

// 让我们用括号来改变优先顺序
fmt.Println(((2 + 1) * m) / n)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

func main() {
// // 优先级: 表达式的顺序
// // 乘法运算符优先运行: * and /

// fmt.Println(
// 1 + 5 - 3*10/2,
// )

// // 3 * 10 = 30
// // 30 / 2 = 15
// // 1 + 5 = 6
// // 6 - 15 = -9

// // **** TIP ****
// // 使用括号来改变顺序
// // 首先, (1+5-3), 然后 (10/2) 将被计算出来

// fmt.Println(
// (1 + 5 - 3) * (10 / 2),
// )
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
celsius := 35.

// 错误的公式: 9*celsius + 160 / 5
// 正确的公式: (9*celsius + 160) / 5
fahrenheit := (9*celsius + 160) / 5

fmt.Printf("%g ºC is %g ºF\n", celsius, fahrenheit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
var n int

// 替代方案:
// n = n + 1
// n += 1

// 较好的:
n++

fmt.Println(n)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

func main() {
n := 10

// 替代方案:
// n = n - 1
// n -= 1

// 较好的:
n--

fmt.Println(n)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

import "fmt"

// 自增自减运算符是一个语句

func main() {
var counter int

// 以下的 "语句" 是正确的:

counter++ // 1
counter++ // 2
counter++ // 3
counter-- // 2
fmt.Printf("There are %d line(s) in the file\n",
counter)

// 以下的 "表达式" 是不正确的:

// counter = 5+counter--
// counter = ++counter + counter--
}
Loading