Introduction to Computer Science/Resource: Moving from Prototype to Polish

Resource: Moving from Prototype to Polish

MDX Parsing Error

[next-mdx-remote] error compiling MDX: Unexpected character `"` (U+0022) in attribute name, expected an attribute name character such as letters, digits, `$`, or `_`; `=` to initialize a value; whitespace before attributes; or the end of the tag More information: https://mdxjs.com/docs/troubleshooting-mdx

Raw Content:



## 🚀 Leveling Up Your Project

As you move from a basic working idea to a final submission, keep these tips in mind. These are the difference between a Level 3 and a Level 4.

#### 1. Crash-Proof Your Input

Don't assume the user will type a number. Use the `.isdigit()` method we discussed!

```python
choice = input("Enter 1 or 2: ")
if choice.isdigit():
    choice = int(choice)
    # ... continue logic
else:
    print("Please enter a number!")

```

#### 2. The "Clean Screen" Trick

Want to make your text game look professional? You can "clear" the screen by printing a bunch of empty lines.

```python
def clear_screen():
    print("\n" * 50)

```

<Callout title="⚠️ The "Spaghetti Code" Warning" type="info">
If your main `while` loop is getting huge (50+ lines), stop! Take chunks of that logic and move them into their own **functions**. Your main loop should just be calling functions like `play_round()`, `show_inventory()`, or `get_score()`.
</Callout>

Interactive Sandbox

Use this space to practice writing code and complete the "Your Turn" activities above.

Python 3Initializing...
Loading code editor...
Program output will appear here...