-
Notifications
You must be signed in to change notification settings - Fork 0
/
goStringFmtEx.go
26 lines (21 loc) · 914 Bytes
/
goStringFmtEx.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
package main
import "fmt"
// Welcome greets a person by name.
func Welcome(name string) string {
return "Welcome to my party, " + name + "!"
}
// HappyBirthday wishes happy birthday to the birthday person and exclaims their age.
func HappyBirthday(name string, age int) string {
s := fmt.Sprintf("Happy birthday %s! You are now %d years old!", name, age)
return s
}
// AssignTable assigns a table to each guest.
func AssignTable(name string, table int, neighbor, direction string, distance float64) string {
s := fmt.Sprintf("Welcome to my party, %s!\nYou have been assigned to table %03d. Your table is %s, exactly %.1f meters from here.\nYou will be sitting next to %s.", name, table, direction, distance, neighbor)
return s
}
func main() {
fmt.Println(Welcome("Christiane"))
fmt.Println(HappyBirthday("Frank", 58))
fmt.Println(AssignTable("Christiane", 27, "Frank", "on the left", 23.7834298))
}