-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
파이썬에서 str타입 확인법
20.01.31 13:16 작성 조회수 143
1
import random
numbers = []
number = str(random.randint(0, 9))
def input_check(msg,casting=str):
while True:
try:
num = casting(input('pop some nums'))
if num.isalpha():
print(num)
else:
print('press this again')
return num
except:
continue
for i in range(3):
while number in numbers:
number = str(random.randint(0,9))
numbers.append(number)
count_strike = 0
count_ball = 0
while count_strike < 3:
count_strike = 0
count_ball = 0
num = input_check('pop nums')
if len(num) == 3:
for i in range(0, 3):
for j in range(0, 3):
if num[i] == numbers[j] and i==j:
count_strike += 1
elif num[i] == numbers[j]and i!=j:
count_ball += 1
if count_strike == 0 and count_ball == 0:
print('3 out')
else:
output = ""
if count_strike > 0:
output += "{} strike".format(count_strike)
if count_ball > 0:
output += "{} ball".format(count_ball)
print(output)
print('exit')
터미널에서 무한 루프가 돌면서
계속 답이 안나오네요 ㅠㅠ 뭐가 문젠지 정확하게 파악이 안되서
코드 올려서 질문 드립니다!
답변을 작성해보세요.
0
남박사
지식공유자2020.01.31
VS 코드보시면 수정은 되었으나 저장되지 않은경우 위의 이미지에서 처럼 파일명 우측에 회색 동그라미 표시가 생깁니다. 그걸 자주보는 습관을 들이시는게 좋습니다. 그리고 꼭 그렇지 않다하더라도 습관적으로 Ctrl + S 를 누르시는 습관이 좋습니다. 어느날 한번쯤은 밤새 작업한 코드를 몽땅 날려먹는 경험을 하실 수 있습니다. ㅎㅎ 제 얘기입니다. ㅜㅜ
0
0
남박사
지식공유자2020.01.31
올려주신 코드를 그대로 복사붙여넣기 해서 돌려봤을때 문제 없이 수행되는걸로 봐서 터미널에서 무한 루프가 돌면서 답이 안나온다는게 무슨 말씀이신지 잘 모르겠습니다. 아래 이미지에서 우클릭 > 새탭에서 이미지열기 하시면 큰 이미지로 보실 수 있습니다.
답변 3