import random
pw =["0", "0", "0"]
pw[0] = str(random.randrange(0,9,1))
pw[1] = pw[0]
pw[2] = pw[0]
def is_correct(guess, password):
if guess == password:
guess_correct = True
else:
guess_correct = False
return guess_correct
response1 ="비밀번호가 틀립니다."
response2 ="안타깝습니다."
response3 ="좀 더 생각해보세요."
MY_PASSWORD = pw
print("환영합니다.n")
answer = str(input("추측하고 계신 비밀번호를 입력하세요(3자리수) : "))
true_or_false = is_correct(answer, MY_PASSWORD)
cnt = 0
while true_or_false == False:
computer_response = random.randint(1, 3)
if computer_response == 1:
cnt += 1
print(response1)
print(cnt,"번 틀렸습니다.")
elif computer_response == 2:
cnt += 1
print(response2)
print(cnt, "번 틀렸습니다.")
else:
cnt += 1
print(response3)
print(cnt, "번 틀렸습니다. ")
a_cnt = 0
for i in range(0,3) :
for j in range(0,3) :
if(answer[i] == str(pw[j]) and i == j):
a_cnt += 1
print("세자리 숫자 중",a_cnt,"개의 숫자가 일치합니다!!")
answer = str(input("n다음 비밀번호는 무엇입니까?"))
true_or_false = is_correct(answer, MY_PASSWORD)
if True :
print ("비밀번호가 일치합니다.",cnt,"번 만에 일치했습니다.")
input("nnn엔터 키를 눌러 종료하세요.")
형님들 파이썬 학교에서 배워야 되서 배우고있슴다. 비밀번호찾기 게임을 만들었는데 문제가 생겼군요. 1.정답으로 안넘어갑니다. 정답을 맞춰도 세자리 숫자 중 1 개의 숫자가 일치합니다!!
세자리 숫자 중 2 개의 숫자가 일치합니다!!
세자리 숫자 중 3 개의 숫자가 일치합니다!! 이런식으로뜨고 2.두자리 숫자만 맞았을때 세자리 숫자 중 1 개의 숫자가 일치합니다!!
세자리 숫자 중 2 개의 숫자가 일치합니다!! 이두개의 메시지가 같이뜹니다.(세자리 숫자 중 2 개의 숫자가 일치합니다!! 이것만 떠야되는데) 해결해주실분 있나욤 ㅠㅠㅠ
댓글 0