28 lines
435 B
Go
28 lines
435 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
)
|
|
|
|
func main() {
|
|
tries := 1
|
|
randNum := rand.Intn(10) + 1 // Generate a number between 1 and 10
|
|
|
|
for tries <= 5 {
|
|
var x int
|
|
fmt.Print("Guess a Number between 1 and 10: ")
|
|
fmt.Scan(&x)
|
|
|
|
if randNum == x {
|
|
fmt.Println("That's great, you got the right number!")
|
|
return
|
|
} else {
|
|
fmt.Println("Guess again")
|
|
}
|
|
tries++
|
|
}
|
|
|
|
fmt.Printf("The right number was %d\n", randNum)
|
|
}
|