Skip to content

Instantly share code, notes, and snippets.

@juliakm
Created February 10, 2020 20:47
Show Gist options
  • Save juliakm/628344d9b80e946590828c4528ca0fdc to your computer and use it in GitHub Desktop.
Save juliakm/628344d9b80e946590828c4528ca0fdc to your computer and use it in GitHub Desktop.
package main
import "github.com/tatsushid/go-prettytable"
import (
"math/rand"
)
func main() {
tbl, err := prettytable.NewTable([]prettytable.Column{
{Header: "Spaceline"},
{Header: "Speed (km/s)"},
{Header: "Trip type"},
{Header: "Price"},
}...)
if err != nil {
panic(err)
}
tbl.Separator = " | "
var count = 0
var spaceline = ""
var speed = 0
var tripType = ""
var min = 16
var max = 30
var price = 0
for count = 10; count > 0; count-- {
if num := rand.Intn(3); num == 0 {
spaceline = "Space Adventures"
} else if num == 1 {
spaceline = "SpaceX"
} else {
spaceline = "Virgin Galactic"
}
speed = rand.Intn(max-min) + min
switch {
case speed > 25:
price = 50
default:
price = 36
}
if tripNum := rand.Intn(2); tripNum == 0 {
tripType = "One-way"
} else {
tripType = "Round-trip"
price = price * 2
}
tbl.AddRow(spaceline, speed, tripType, price)
}
tbl.Print()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment