forked from unknwon/the-way-to-go_ZH_CN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request unknwon#319 from appleboy/patch-5
fix: coding style and file format for chapter 8.
- Loading branch information
Showing
2 changed files
with
110 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
// map_days.go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
var Days = map[int]string{1:"monday", | ||
2:"tuesday", | ||
3: "wednesday", | ||
4: "thursday", | ||
5: "friday", | ||
6: "saturday", | ||
7: "sunday"} | ||
|
||
func main() { | ||
fmt.Println(Days) | ||
// fmt.Printf("%v", Days) | ||
flagHolliday := false | ||
for k, v := range Days { | ||
if v == "thursday" || v == "holliday" { | ||
fmt.Println(v, " is the ", k , "th day in the week") | ||
if v == "holliday" { | ||
flagHolliday = true | ||
} | ||
} | ||
} | ||
if !flagHolliday { | ||
fmt.Println("holliday is not a day!") | ||
} | ||
} | ||
/* Output: | ||
thursday is the 4 th day in the week | ||
holliday is not a day! | ||
*/ | ||
// map_days.go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
var Days = map[int]string{1: "monday", | ||
2: "tuesday", | ||
3: "wednesday", | ||
4: "thursday", | ||
5: "friday", | ||
6: "saturday", | ||
7: "sunday"} | ||
|
||
func main() { | ||
fmt.Println(Days) | ||
// fmt.Printf("%v", Days) | ||
flagHolliday := false | ||
for k, v := range Days { | ||
if v == "thursday" || v == "holliday" { | ||
fmt.Println(v, " is the ", k, "th day in the week") | ||
if v == "holliday" { | ||
flagHolliday = true | ||
} | ||
} | ||
} | ||
if !flagHolliday { | ||
fmt.Println("holliday is not a day!") | ||
} | ||
} | ||
|
||
/* Output: | ||
thursday is the 4 th day in the week | ||
holliday is not a day! | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,74 @@ | ||
// map_drinks.go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
) | ||
|
||
func main() { | ||
drinks := map[string]string{ | ||
"beer": "bière", | ||
"wine": "vin", | ||
"water": "eau", | ||
"coffee": "café", | ||
"thea": "thé"} | ||
sdrinks := make([]string, len(drinks)) | ||
ix := 0 | ||
|
||
fmt.Printf("The following drinks are available:\n") | ||
for eng := range drinks { | ||
sdrinks[ix] = eng | ||
ix++ | ||
fmt.Println(eng) | ||
} | ||
|
||
fmt.Println("") | ||
for eng, fr := range drinks { | ||
fmt.Printf("The french for %s is %s\n", eng, fr) | ||
} | ||
|
||
// SORTING: | ||
fmt.Println("") | ||
fmt.Println("Now the sorted output:") | ||
sort.Strings(sdrinks) | ||
|
||
fmt.Printf("The following sorted drinks are available:\n") | ||
for _, eng := range sdrinks { | ||
fmt.Println(eng) | ||
} | ||
|
||
fmt.Println("") | ||
for _, eng := range sdrinks { | ||
fmt.Printf("The french for %s is %s\n", eng, drinks[eng]) | ||
} | ||
} | ||
/* Output: | ||
The following drinks are available: | ||
wine | ||
beer | ||
water | ||
coffee | ||
thea | ||
The french for wine is vin | ||
The french for beer is bière | ||
The french for water is eau | ||
The french for coffee is café | ||
The french for thea is thé | ||
Now the sorted output: | ||
The following sorted drinks are available: | ||
beer | ||
coffee | ||
thea | ||
water | ||
wine | ||
The french for beer is bière | ||
The french for coffee is café | ||
The french for thea is thé | ||
The french for water is eau | ||
The french for wine is vin | ||
*/ | ||
// map_drinks.go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
) | ||
|
||
func main() { | ||
drinks := map[string]string{ | ||
"beer": "bière", | ||
"wine": "vin", | ||
"water": "eau", | ||
"coffee": "café", | ||
"thea": "thé"} | ||
sdrinks := make([]string, len(drinks)) | ||
ix := 0 | ||
|
||
fmt.Printf("The following drinks are available:\n") | ||
for eng := range drinks { | ||
sdrinks[ix] = eng | ||
ix++ | ||
fmt.Println(eng) | ||
} | ||
|
||
fmt.Println("") | ||
for eng, fr := range drinks { | ||
fmt.Printf("The french for %s is %s\n", eng, fr) | ||
} | ||
|
||
// SORTING: | ||
fmt.Println("") | ||
fmt.Println("Now the sorted output:") | ||
sort.Strings(sdrinks) | ||
|
||
fmt.Printf("The following sorted drinks are available:\n") | ||
for _, eng := range sdrinks { | ||
fmt.Println(eng) | ||
} | ||
|
||
fmt.Println("") | ||
for _, eng := range sdrinks { | ||
fmt.Printf("The french for %s is %s\n", eng, drinks[eng]) | ||
} | ||
} | ||
|
||
/* Output: | ||
The following drinks are available: | ||
wine | ||
beer | ||
water | ||
coffee | ||
thea | ||
The french for wine is vin | ||
The french for beer is bière | ||
The french for water is eau | ||
The french for coffee is café | ||
The french for thea is thé | ||
Now the sorted output: | ||
The following sorted drinks are available: | ||
beer | ||
coffee | ||
thea | ||
water | ||
wine | ||
The french for beer is bière | ||
The french for coffee is café | ||
The french for thea is thé | ||
The french for water is eau | ||
The french for wine is vin | ||
*/ |