| | import streamlit as st |
| |
|
| | |
| | st.title("SUBR Game: Stack Underflow Bug Riddle") |
| |
|
| | |
| | st.write(""" |
| | Welcome to the SUBR Game! Your goal is to find the stack underflow bug in the given code snippet. |
| | Solve the riddle and submit your answer to see if you're correct! |
| | """) |
| |
|
| | |
| | code_snippet = """ |
| | def calculate_sum(numbers): |
| | total = 0 |
| | for i in range(len(numbers) - 1, -1, -1): |
| | total += numbers[i] |
| | return total |
| | |
| | numbers = [1, 2, 3, 4, 5] |
| | result = calculate_sum(numbers) |
| | print("The sum is:", result) |
| | """ |
| |
|
| | st.code(code_snippet, language='python') |
| |
|
| | |
| | user_answer = st.text_input("What is the stack underflow bug in the code above?", "") |
| |
|
| | |
| | correct_answer = "The bug is in the loop range; it should be `range(len(numbers) - 1, -1, -1)` to avoid underflow." |
| |
|
| | |
| | if st.button("Submit"): |
| | if user_answer.strip().lower() == correct_answer.lower(): |
| | st.success("Congratulations! You found the bug!") |
| | else: |
| | st.error("Sorry, that's not correct. Try again!") |
| |
|
| | |
| | st.write(""" |
| | This is a simple example of a SUBR game. You can expand it with more complex code snippets and riddles. |
| | """) |