projectx / guess_the_number_game.py
Wallacefaz's picture
Create guess_the_number_game.py
62444e7 verified
raw
history blame contribute delete
961 Bytes
import gradio as gr
import random
# Variável global para armazenar o número alvo
target_number = random.randint(1, 100)
def check_guess(guess):
global target_number
if guess < target_number:
return "Try a higher number!"
elif guess > target_number:
return "Try a lower number!"
else:
target_number = random.randint(1, 100) # Reset the game with a new number
return "Congratulations! You guessed it! Let's play again."
# Interface do Gradio
with gr.Blocks() as demo:
gr.Markdown("### Guess the Number Game")
gr.Markdown("Guess a number between 1 and 100")
with gr.Row():
with gr.Column():
input_number = gr.Number(label="Your Guess", value=1, precision=0)
output_text = gr.Textbox(label="Result")
guess_button = gr.Button("Guess")
guess_button.click(fn=check_guess, inputs=input_number, outputs=output_text)
demo.launch()