-
Notifications
You must be signed in to change notification settings - Fork 0
/
P-B0523-4.py
139 lines (99 loc) · 3.74 KB
/
P-B0523-4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'''from tkinter import *
window = Tk()
def changeimg () :
k = entry.get()
img = PhotoImage (file = k)
imagelabel.configure (image = img)
imagelabel.image = img
rabbit = PhotoImage (file = "/Users/alphastation/Desktop/컴퓨터공학전공/repository/learningpython/img/rabbit.GIF")
imagelabel = Label (window, image = rabbit)
imagelabel.pack()
text = Label (window, text = "아래에 경로 입력")
text.pack()
entry = Entry (window, bg = "lightgray", fg = "white")
entry.pack()
button = Button (window, text = "submit", command = changeimg)
button.pack()
window.mainloop()'''
# 컴퓨터가 내는 수학 문제를 맞추면 고양이가 환호하는 사진, 맞추지 못하면 고양이가 속상해하는 사진 출력하기
import random
from tkinter import *
from PIL import Image, ImageTk
window = Tk()
# selection algorithm
'''if op1 == 1 :
if op2 == 1 :
if op3 == 1 :
elif op3 == 2 :
elif op3 == 3 :
elif op3 == 4 :
elif op2 == 2 :
if op3 == 1 :
elif op3 == 2 :
elif op3 == 3 :
elif op3 == 4 :
elif op2 == 3 :
if op3 == 1 :
elif op3 == 2 :
elif op3 == 3 :
elif op3 == 4 :
elif op2 == 4 :
if op3 == 1 :
elif op3 == 2 :
elif op3 == 3 :
elif op3 == 4 : ''' # 더 이상은 노역이자 노가다
a = random.randint (0, 100)
b = random.randint (0, 100)
c = random.randint (0, 100)
d = random.randint (0, 100)
# 소수점이 생기지 않게끔 (정수형이 나오게끔) / 기호 없앰
operators = ['+', '-', '*']
variables = [a, b, c, d]
expressions = []
# 4개의 변수에 대한 모든 조합 생성
for i, a in enumerate(variables):
for j, b in enumerate(variables):
if j == i:
continue
for k, c in enumerate(variables):
if k == i or k == j:
continue
for l, d in enumerate(variables):
if l == i or l == j or l == k:
continue
# 사칙연산 연산자를 포함한 식 생성
for op1 in operators:
for op2 in operators:
for op3 in operators:
expression = f"{a} {op1} {b} {op2} {c} {op3} {d}"
expressions.append(expression)
# 결과 출력
for expression in expressions:
print(expression)
def confirm():
global l # 전역 변수 선언
inp = float(e1.get())
if inp == ans:
img = ImageTk.PhotoImage(Image.open("/Users/alphastation/Desktop/컴퓨터공학전공/repository/practice-learningpython/good.jpeg"))
l.configure(image=img) # 이미지 업데이트
l.image = img # 이미지 객체에 대한 참조 유지
elif inp != ans:
img = ImageTk.PhotoImage(Image.open("/Users/alphastation/Desktop/컴퓨터공학전공/repository/practice-learningpython/180-1801869_report-abuse-sad-cat-dank-memes.jpeg"))
l.configure(image=img) # 이미지 업데이트
l.image = img # 이미지 객체에 대한 참조 유지
realans = Label(window, text="정답은 " + str(ans))
realans.pack()
formula = random.choice(expressions)
ans = eval(formula) # 식을 계산하는 함수 eval
print (ans)
l1 = Label(window, text="컴퓨터가 내는 문제를 맞춰보세요!")
l2 = Label(window, text=formula, fg="blue")
l1.pack()
l2.pack()
e1 = Entry(window)
btn = Button(window, text="결과 제출", command=confirm)
e1.pack()
btn.pack()
l = Label(window) # 이미지를 표시할 라벨 생성
l.pack()
window.mainloop()