반응형
사용자가 1과 4 사이의 숫자를 입력하도록하려고합니다. 숫자가 올바른지 확인하는 코드가 있지만 숫자가 정확할 때까지 코드를 여러 번 반복하고 싶습니다. 누구든지 이것을하는 방법을 알고 있습니까? 코드는 다음과 같습니다.
def Release():
try:
print 'Please select one of the following?\nCompletion = 0\nRelease ID = 1\nVersion ID = 2\nBuild ID = 3\n'
a = int(input("Please select the type of release required: "))
if a == 0:
files(a)
elif a == 1:
files(a)
elif a == 2:
files(a)
elif a == 3:
files(a)
else:
raise 'incorrect'
except 'incorrect':
print 'Try Again'
except:
print 'Error'
Release()
입력 한 예외에 대한 오류도 표시됩니다.
kill.py:20: DeprecationWarning: catching of string exceptions is deprecated
except 'incorrect':
Error
도움을 주셔서 감사합니다
해결 방법
def files(a):
pass
while True:
try:
i = int(input('Select: '))
if i in range(4):
files(i)
break
except:
pass
print '\nIncorrect input, try again'
참조 페이지 https://stackoverflow.com/questions/2244270
반응형
'파이썬' 카테고리의 다른 글
파이썬 현재 txt를 덮어 쓰지 않고 파일에 파이썬 쓰기 (0) | 2020.12.20 |
---|---|
파이썬 `sorted (list)`와`list.sort ()`의 차이점은 무엇입니까? (0) | 2020.12.20 |
파이썬 Python : matplotlib를 사용하여 그린 그래프의 기울기를 찾는 방법은 무엇입니까? (0) | 2020.12.19 |
파이썬 Chrome 브라우저를 열기위한 Python webbrowser.open () (0) | 2020.12.19 |
파이썬 boto를 사용하여 AWS S3 버킷을 연결할 수 없음 (0) | 2020.12.19 |
댓글