Notice
Recent Posts
Recent Comments
«   2024/04   »
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 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

CHIqueen

Golang Guessing game 게싱게임 본문

프로그래밍/Golang

Golang Guessing game 게싱게임

CHIqueen 2020. 6. 6. 01:30
package main

import(
	"fmt"
	"math/rand"
	"time"
)

func main(){
	fmt.Println("Guessing game")
	rand.Seed(time.Now().UnixNano())
	secNum := rand.Intn(100)

	var guess int

	for {
		fmt.Scan(&guess)
		fmt.Println("You guessed", guess)

		if guess < secNum {
			fmt.Println("Up")
		} else if guess > secNum {
			fmt.Println("Down")
		} else {
			fmt.Println("Correct!")
			break
		}
	}
}

간단한 Go 언어 예제

 

math/rand와 time을 사용했다.

 

'프로그래밍 > Golang' 카테고리의 다른 글

영화관 개봉정보 크롤링 vol.1  (0) 2022.09.01
Comments