사용자 입력을위한 추측 프로그램을 1 - 100 범위 내에서 작성합니다.왜 파이썬 코드가 while 루프를 건너 뛸까요?
사용자 입력을 확인하고 전달하는 두 번째 while 루프를 건너 뛰는 이유는 무엇입니까? 그것은 바로
import random
nums_lasted = []
a = 0
while a < 101:
nums_lasted.append(a)
a += 1
secret_num = 1
while secret_num < 0 or secret_num > 100:
try:
secret_num = int(input("My number is"))
except ValueError:
print("No way that was an integer!")
guess_pc = 50
min = 50
max = 101
while True:
print("Is it", guess_pc,"?")
if guess_pc == secret_num:
print("Easy")
break
elif guess_pc > secret_num:
max = guess_pc
nums_lasted.append(guess_pc)
nums_lasted1 = [i for i in nums_lasted if i < guess_pc]
nums_lasted = nums_lasted1
elif guess_pc < secret_num:
min = guess_pc
nums_lasted.append(guess_pc)
nums_lasted1 = [i for i in nums_lasted if i < guess_pc]
nums_lasted = nums_lasted1
guess_pc = random.choice(nums_lasted)
힌트 : '1 < 0 or 1 > 100'의 진리 값은 무엇입니까? – Kevin
BTW, 파이썬에서 'secret_num == 1'일 때'0 =