2014-08-29 2 views
0

다음 Jython 프로그램에서 정답을 얻을 때까지 사용자가 추측 할 수 있도록 while 루프를 포함하려면 어떻게해야합니까?While 자이 썬 무작위 모듈 루프

import random 

def numberGuess(): 
    printNow("I'm thinking of a number between 1 and 10") 
    guess = 0 
    randNum = random.randrange(1,11) 
    guess = int(input("Try to guess the number: ")) 
    if guess > 10: 
     print("Wrong! You guessed too high") 
    elif guess < 1: 
     print("Wrong! You guessed too low") 
    else : 
     print(" you got it") 

답변

1

이 시도 :

import random 

while True: 
    print("I'm thinking of a number between 1 and 10") 
    randNum = random.randrange(1, 11) 
    guess = int(input("Try to guess the number: ")) 
    if guess == randNum: 
     print("You got it") 
     break 
    else: 
     if guess > 10: 
      print("Wrong! You guessed too high") 
     elif guess < 1: 
      print("Wrong! You guessed too low") 
+0

는 아무것도 안하고 및 중 어떤 오류가 표시되지 않습니다. –

+0

나는 내 대답을 편집했는데, 그 이유는 모든 것이 'while' 루프 내에 있어야하기 때문입니다. –

+0

======= Progam로드 ======= 숫자를 추측 해보십시오 : –