In this coding challenge, youโ€™ll implement a function that reverses each word in a sentence while maintaining word order. For example, โ€œHello Worldโ€ should become โ€œolleH dlroWโ€. Try implementing the reverse_words function below!

Code
import gradio as gr

def reverse_words(sentence):
    # You should implement: "Hello World" -> "olleH dlroW"
    # return " ".join(word[::-1] for word in sentence.split())
    return "CHANGE ME"

def check_solution(user_input):
    correct = " ".join(word[::-1] for word in user_input.split())
    user_result = reverse_words(user_input)
    return user_result, correct, "โœ… Correct!" if user_result == correct else "โŒ Try again!"

with gr.Blocks() as demo:
    gr.Markdown("# Reverse Words Challenge")
    input_text = gr.Textbox(label="Sentence", value="Hello World")
    output_user = gr.Textbox(label="Your Output")
    output_correct = gr.Textbox(label="Expected")
    result = gr.Textbox(label="Result")
    gr.Button("Check").click(check_solution, input_text, [output_user, output_correct, result])

demo.launch()
import gradio as gr def reverse_words(sentence): # You should implement: "Hello World" -> "olleH dlroW" # return " ".join(word[::-1] for word in sentence.split()) return "CHANGE ME" def check_solution(user_input): correct = " ".join(word[::-1] for word in user_input.split()) user_result = reverse_words(user_input) return user_result, correct, "โœ… Correct!" if user_result == correct else "โŒ Try again!" with gr.Blocks() as demo: gr.Markdown("# Reverse Words Challenge") input_text = gr.Textbox(label="Sentence", value="Hello World") output_user = gr.Textbox(label="Your Output") output_correct = gr.Textbox(label="Expected") result = gr.Textbox(label="Result") gr.Button("Check").click(check_solution, input_text, [output_user, output_correct, result]) demo.launch()