soJaeyoon commited on
Commit
164a4d7
Β·
verified Β·
1 Parent(s): 4946e6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -28
app.py CHANGED
@@ -1,32 +1,18 @@
1
  import random
2
  import gradio as gr
3
 
4
- def run_game(direction):
5
- player_position = 0
6
- obstacle_position = 5
7
-
8
- if direction == "Left":
9
- player_position -= 1
10
- elif direction == "Right":
11
- player_position += 1
12
-
13
- # μž₯μ• λ¬Όκ³Ό 좩돌 체크
14
- if player_position == obstacle_position:
15
- return "Game Over"
16
-
17
- # μƒμžμ— λ„μ°©ν•œ 경우
18
- if player_position == 10:
19
- return "You Win!"
20
-
21
- # ν˜„μž¬ μœ„μΉ˜ ν‘œμ‹œ
22
- game_map = [" "] * 10
23
- game_map[player_position] = "P"
24
- game_map[obstacle_position] = "O"
25
-
26
- return " | ".join(game_map)
27
-
28
- iface = gr.Interface(fn=run_game, inputs="text", outputs="text", title="Keyboard Controlled Game", description="Use 'Left' and 'Right' keys to move the player. Avoid obstacle 'O' and reach the box 'P'.")
29
  iface.launch()
30
-
31
-
32
-
 
1
  import random
2
  import gradio as gr
3
 
4
+ def guess_number(user_input):
5
+ # 컴퓨터가 μ„ νƒν•œ 랜덀 숫자 생성
6
+ computer_number = random.randint(1, 100)
7
+
8
+ # μ‚¬μš©μž μž…λ ₯κ³Ό 컴퓨터 숫자 비ꡐ
9
+ user_number = int(user_input)
10
+ if user_number == computer_number:
11
+ return f"μ •λ‹΅μž…λ‹ˆλ‹€! 컴퓨터가 μ„ νƒν•œ μˆ«μžλŠ” {computer_number}μž…λ‹ˆλ‹€."
12
+ elif user_number < computer_number:
13
+ return "더 큰 숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”."
14
+ else:
15
+ return "더 μž‘μ€ 숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”."
16
+
17
+ iface = gr.Interface(fn=guess_number, inputs="text", outputs="text", title="숫자 λ§žμΆ”κΈ° κ²Œμž„", description="1μ—μ„œ 100 μ‚¬μ΄μ˜ 숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”.")
 
 
 
 
 
 
 
 
 
 
 
18
  iface.launch()