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

제목[re]실습자료 LOOP_PART_2 질문입니다2022-04-25 23:22
작성자

import random


print("Make your magic number (1...100)")

input(prompt="Please enter to start.")


limitLow = 1

limitHigh = 101


while True:

    intRandom = random.randrange(limitLow, limitHigh)

    print("My guess: ", intRandom)

    userInput = int(input(prompt="Enter your answer - lower(0), equal(1), larger(2): "))

    if(userInput == 1): # equal

        print("Matched.")

        break

    elif(userInput == 0): # lower

        print("Move to lower range")

        limitHigh = intRandom

    else: #larger

        print("Move to higher range")

        limitLow = intRandom + 1


#### 이 과정에서 LIMITLOW 라는 변수를 따로 두지 않고, 바로 1 로 두고, INTRANDOM = RANDOM.RANDRANGE(1,101)로 하면 안되나요??


코드 내에서 변수를 재설정해주는 부분이 있으므로 안 됩니다. 랜덤을 계속 1~100 사이에서 돌리는게 아니라, 변수를 이용해 바꿔주고 있네요.

댓글