Update app.py
Browse files
app.py
CHANGED
@@ -3,21 +3,28 @@ import random as rd
|
|
3 |
rand = rd.randint(0,9)
|
4 |
def guess(num):
|
5 |
num = int(num)
|
6 |
-
if num == rand:
|
7 |
r = 'ทายถูกแล้ว'
|
8 |
else:
|
9 |
r = 'ลองกดใหม่ดู'
|
10 |
return r
|
11 |
def answer():
|
12 |
-
return '
|
|
|
|
|
|
|
|
|
|
|
13 |
with gr.Blocks() as myApp:
|
14 |
with gr.Row():
|
15 |
with gr.Column(scale=1):
|
16 |
inp=gr.Radio(choices=list(range(10)),label='เลือก1หมายเลข')
|
17 |
btn = gr.Button(Value="เฉลย")
|
|
|
18 |
with gr.Column(scale=1):
|
19 |
out = gr.Textbox(label='ผลลัพธ์')
|
20 |
inp.change(guess,inp,out)
|
21 |
btn.click(fn=answer,outputs=out)
|
|
|
22 |
myApp.launch()
|
23 |
|
|
|
3 |
rand = rd.randint(0,9)
|
4 |
def guess(num):
|
5 |
num = int(num)
|
6 |
+
if num == rand[0]:
|
7 |
r = 'ทายถูกแล้ว'
|
8 |
else:
|
9 |
r = 'ลองกดใหม่ดู'
|
10 |
return r
|
11 |
def answer():
|
12 |
+
return 'เลขที่สุ่มได้คือ'+str(rand)
|
13 |
+
|
14 |
+
def newRand():
|
15 |
+
rand[0]=rd.randint(0,9)
|
16 |
+
return str(rand)
|
17 |
+
|
18 |
with gr.Blocks() as myApp:
|
19 |
with gr.Row():
|
20 |
with gr.Column(scale=1):
|
21 |
inp=gr.Radio(choices=list(range(10)),label='เลือก1หมายเลข')
|
22 |
btn = gr.Button(Value="เฉลย")
|
23 |
+
btn2 = gr.Button(value="สุ่มใหม่")
|
24 |
with gr.Column(scale=1):
|
25 |
out = gr.Textbox(label='ผลลัพธ์')
|
26 |
inp.change(guess,inp,out)
|
27 |
btn.click(fn=answer,outputs=out)
|
28 |
+
btn2.click(fn=newRand,outputs=out)
|
29 |
myApp.launch()
|
30 |
|