Created
March 14, 2020 10:42
-
-
Save timolinn/53767dcaf95b45d64528e7e29ae09225 to your computer and use it in GitHub Desktop.
Guessing Game written in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
func main() { | |
fmt.Println("Guess the number!") | |
// generate a random number | |
source := rand.NewSource(time.Now().UnixNano()) | |
randomizer := rand.New(source) | |
secretNumber := randomizer.Intn(10) // generates numbers between 0 and n (10) | |
var guess int | |
for { | |
fmt.Println("Please input your guess: ") | |
fmt.Scan(&guess) | |
if guess > secretNumber { | |
fmt.Println("Too Big") | |
} else if guess < secretNumber { | |
fmt.Println("Too small") | |
} else { | |
fmt.Println("You win! 🥳") | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment