값이 0보다 큰지, 숫자인지 확인하기 위해 내 코드에서 가져온 것이 있습니다.
while(1):
n = input("Type a number of rolls to do, to try and get 3 of the same sides in a row.")
if n.isdigit() and int(n) > 0 == True:
n = int(n)
break
else:
print("Select a proper integer.")
어떤 이유로 10과 같이 루프를 중지해야하는 값을 입력하면 잘못된 정수로 간주됩니다. 왜 그런 겁니까?
오류를 제외하고이를 수행하는 "올바른"방법 (특히 int(n)
두 번 호출하지 않음 )은 다음에서 발생한 예외를 포착하는 것입니다 int(n)
.
while True:
n = input("Type a number...")
try:
n = int(n)
except ValueError:
continue
if n > 0:
break
print("Select a positive integer")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다