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

제목step 12 마지막문제 질문드립니다!2021-04-13 20:10
작성자
print("Guess the number chosen by name")
print("If the number is smaller than the correct number, enter 0\nIf the number is bigger than the correct number, enter 2\nIf the number is correct, eneter 1")
print("Let's start!")
print()

first = 1
last = 100
import random
py = random.randrange(first, last)
print(py)

myanswer = int(input("write your answer: "))

while myanswer == 0 or 2 or 1:
   
    if myanswer == 0:
        first  = py+1
        py = random.randrange(first, last)
        print(py)
        myanswer = int(input("write your answer: "))
        continue
        
    if myanswer == 2:
        last = py
        py = random.randrange(first, last)
        print(py)
        myanswer = int(input("write your answer: "))
        continue
        
    if myanswer == 1:
        print()
        print("Correct answer!")
        break

이렇게 코드를 짜면 결국 답이 나오긴합니다. 근데 여기서 노트북이 물어보는 숫자의 크기가 fistr와 last의 중간값으로 만들고 싶은데, 어떤 식으로 작성하면 되나요?? 조언 부탁드립니다!
댓글