File size: 530 Bytes
fd35dd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
import random

mole_pos = random.randint(1, 9)

def whack(choice):
    global mole_pos
    result = "打中了!" if int(choice) == mole_pos else "沒打中!"
    mole_pos = random.randint(1, 9)
    return result

iface = gr.Interface(fn=whack,
                     inputs=gr.Radio(choices=[str(i) for i in range(1, 10)], label="選擇洞口"),
                     outputs="text",
                     title="打地鼠遊戲",
                     description="點選你想打的洞口!")
iface.launch()