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 grdef 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()