import random
def gen():
return [random.randint(1, 6) for _ in range(3)]
def score(u, c):
s = 0
for x, y in zip(u, c):
if x > y:
s += 3
elif x == y:
s += 1
else:
s -= 2
return s
def max_sum(u, c, r):
rev = c[r]
rem = [n for i, n in enumerate(c) if i != r]
user_max = max(u)
max_possible = 0
for num in rem:
if num < user_max:
max_possible = max(max_possible, user_max - 1 + num)
elif num == user_max:
max_possible = max(max_possible, user_max + num)
else:
max_possible = max(max_possible, 6 + num)
return max_possible
def main():
while True:
c = gen()
u = gen()
sc = score(u, c)
r = random.randint(0, 2)
rev = c[r]
print(f"\n사용자의 숫자: {u}")
print(f"총 점수: {sc}")
print(f"컴퓨터 숫자 중 공개된 숫자: 위치 {r + 1}번째 숫자는 {rev}입니다.")
m = max_sum(u, c, r)
g = int(input("나머지 두 숫자의 합의 최대값을 맞추세요: "))
if g == m:
print("정답입니다!")
else:
print(f"틀렸습니다. 나머지 두 숫자의 최대값은 {m}입니다.")
print(f"컴퓨터의 모든 숫자: {c}")
cont = input("\n계속 하려면 엔터를 누르세요. 그만 하려면 '그만'이라고 입력하세요: ")
if cont.lower() == '그만':
print("게임을 종료합니다.")
break
#if __name__ == "__main__":
# main()
main()
To embed this project on your website, copy the following code and paste it into your website's HTML: