package main import ( "fmt" "github.com/dariubs/percent" "strings" ) var alphabet = []rune{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', } func letterCount(inputText string) { count := make([]int, len(alphabet)) frequency := make([]float64, len(alphabet)) totalCount := 0 for index, letter := range alphabet { count[index] = strings.Count(inputText, string(letter)) count[index] += strings.Count(inputText, string(letter+32)) totalCount += count[index] } for index := range alphabet { frequency[index] = percent.PercentOf(count[index], totalCount) } for index, letter := range alphabet { fmt.Printf("The letter %c (%c) occurs %d times in the text and the frequency in percent is %0.2f\n", letter, letter+32, count[index], frequency[index]) } } func main() { letterCount("This is a test to check for something.Zz") }