컴퓨터/프로그래밍

1부터 100까지 숫자중 임의의 숫자 추측하기

review777777 2011. 8. 5. 02:53
반응형

1부터 100까지 숫자중 임의의 숫자 추측하기

 

from random import randint

secret = randint(1,100)

print("Welcome!")

guess=0

while guess!=secret:

g=input("Guess the number:")

guess=int(g)

if guess ==secret:

print("You win!")

else:

if guess > secret :

print("Too high")

else:

print("Too low")

print("Game over!")

 

 

 

 

 

 

 

from random import randint

secret = randint(1,100)

-> 랜덤으로 1부터 100까지 임의의 수로 설정

 

 

print(“”)

-> 출력하게 함.

 

 

while guess!=secret:

-> while . secret과 같지 않는 숫자가 나오면 무한루프.

g=input("Guess the number:")

guess=int(g)

-> 변수 g에 추측한 숫자를 저장하고 변수 gguess에 저장.

 

 

if guess ==secret:

print("You win!")

else:

if guess > secret :

print("Too high")

else:

print("Too low")

->ifelse를 이용

반응형

'컴퓨터 > 프로그래밍' 카테고리의 다른 글

chapter 02  (0) 2011.08.05
웹에서 텍스트 가져오기  (0) 2011.08.05
python 처음 시작하기  (0) 2011.08.05
05-07  (0) 2011.06.16
05-04  (0) 2011.06.16
05-02  (0) 2011.05.11
04-03  (0) 2011.05.11