generated from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountries.go
64 lines (54 loc) · 1.43 KB
/
countries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
// CountryInfo represents information about a country
type CountryInfo struct {
FlagColors []string
Continent string
}
func main() {
countries := map[string]CountryInfo{
"france": {
FlagColors: []string{"Blue", "White", "Red"},
Continent: "Europe",
},
"japan": {
FlagColors: []string{"Red", "White"},
Continent: "Asia",
},
"brazil": {
FlagColors: []string{"Green", "Yellow", "Blue", "White"},
Continent: "South America",
},
// Add more countries as needed
}
reader := bufio.NewReader(os.Stdin)
fmt.Println("Welcome to the Country Info App!")
for {
countryName := getUserInput("Enter a country name (or 'exit' to quit): ", reader)
// Check if the user wants to exit
if strings.ToLower(countryName) == "exit" {
fmt.Println("Exiting the Country Info App. Goodbye!")
return
}
// Lookup country information
info, found := countries[strings.ToLower(countryName)]
if !found {
fmt.Println("Country not found. Please enter a valid country name.")
continue
}
// Print country information
fmt.Printf("Flag Colors: %s\n", strings.Join(info.FlagColors, ", "))
fmt.Printf("Continent: %s\n", info.Continent)
}
}
// getUserInput gets user input from the console
func getUserInput(prompt string, reader *bufio.Reader) string {
fmt.Print(prompt)
input, _ := reader.ReadString('\n')
return strings.TrimSpace(strings.ToLower(input))
}