#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목practice_11_loop_part_2 관련 질문2024-10-14 20:10
작성자

안녕하세요. 


해당 코드에서 while문 안의 random 값이 변하지 않는데, 왜 그런지 궁금합니다. 

import random을 한 뒤에, intRandom을 두번이나 랜덤 값을 주었는데 다른 것을 봐서, 랜덤 값이 고정되어 있지는 않은 것 같아 보임니다..


감사합니다.  



print("Hello. I will guess your number.")


import random


intRandom=random.randrange(0, 100)

print(intRandom)

L=100  #large

S=0  #Smaller


intRandom=random.randrange(0, 100)

print(intRandom)


while (intRandom<=L and intRandom>=S):

    userInput=input("It is the value {} think. is it okay? : smaller(0), same(1), larger(2)\n".format(intRandom))

    if (userInput==1):

        print("Good. The number is {}".format(intRandom))

        continue

    elif (userInput==2):

        print("Okay. I will guess more larger number.")

        S=intRandom+1

        intRandom=random.randrange(S, L)

        

        continue

    elif (userInput==0):

        print("Okay. I will guess more smaller number.")

        L=intRandom-1

        intRandom=random.randrange(S, L)

        continue

        

댓글