import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLineEdit, QLabel
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.n1 = int(0)
self.n2 = int(0)
self.n3 = int(0)
self.a1 = int(0)
self.a2 = int(0)
self.a3 = int(0)
self.b = int(0)
self.s = int(0)
self.data = list()
import random # 숫자 생성
self.n1 = random.randrange(0, 10)
self.n2 = random.randrange(0, 10)
while self.n1 == self.n2:
self.n2 = random.randrange(0, 10)
self.n3 = random.randrange(0, 10)
while self.n1 == self.n3 or self.n2 == self.n3:
self.n3 = random.randrange(0, 10)
print(self.n1, self.n2, self.n3)
def initUI(self):
self.setWindowTitle('숫자 야구')
L = QVBoxLayout()
self.setLayout(L)
self.ex = QLabel('공백으로 구별해 세 숫자 입력', self)
L.addWidget(self.ex)
self.line = QLineEdit(self)
L.addWidget(self.line)
self.line.editingFinished.connect(self.Finish)
self.label = QLabel('', self)
L.addWidget(self.label)
self.move(300, 300)
self.resize(400, 200)
self.show()
def Finish(self):
self.data = list(self.line.text())
self.a1 = int(self.data[0])
self.a2 = int(self.data[2])
self.a3 = int(self.data[4])
if self.a1 == self.n1:#스트라이크
self.s += 1
if self.a2 == self.n2:
self.s += 1
if self.a3 == self.n3:
self.s += 1
if self.a1 == self.n2 or self.a1 == self.n3:#볼
self.b += 1
if self.a2 == self.n1 or self.a2 == self.n3:
self.b += 1
if self.a3 == self.n1 or self.a3 == self.n2:
self.b += 1
if self.s == 3:#맞췄다면?
self.label.setText(self.label.text() + '\n' + str(self.a1) + str(self.a2) + str(self.a3) + '\n정답\n')
elif self.s == 0 and self.b == 0:
self.label.setText(self.label.text() + '\n' + str(self.a1) + str(self.a2) + str(self.a3) + '\nOUT\n')
else :
self.label.setText(self.label.text() + '\n' + str(self.a1) + str(self.a2) + str(self.a3))
self.label.setText(self.label.text() + '\n' + str(self.s) + 'S ' + str(self.b) + 'B' + '\n')
self.b = 0
self.s = 0
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
top of page
기능을 테스트하려면 라이브 사이트로 이동하세요.
수정: 22시간
2025.1.17 ||숫자야구
2025.1.17 ||숫자야구
댓글 0개
좋아요
댓글(0)
bottom of page