

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
Back
ctrl+,
Next
ctrl+.
Up until this point, all the coding lessons you've completed have been testing you based on your code's console output (what's printed). For example, a lesson might expect your code (in conjunction with the code we provide) to print something like:
Armor: 2
Health: 18
If your code prints that exact output, you pass. If it doesn't, you fail.
Going forward, you'll encounter a new type of lesson: unit tests. A unit test is just an automated program that tests a small "unit" of code. Usually just a function or two. The editor will have tabs: the 'main.py' file containing your code, and the 'main_test.py' file containing the unit tests. The shortcut to switch tabs is typically Alt+Shift+[ on QWERTY keyboards. This shortcut may vary depending on your keyboard layout.
These new unit-test-style lessons will test your code's functionality rather than its output. Our tests will call functions in your code with different arguments, and expect certain return values. If your code returns the correct values, you pass. If it doesn't, you fail.
There are two reasons for this change:
print statements, and leave those print statements in when you submit. Unlike the output-based lessons, you won't have to remove your print statements to pass.Also, ▶ Run and ▶ Submit work a little differently than before. When you run your code, it only runs some of the tests, but when you submit your code, it runs all of the tests. This is to simulate a production environment with unexpected edge cases and to teach you to think them through. Luckily for you, all of the tests are visible in the main_test.py file tab, so be sure to check it before submitting.
Complete the total_xp function. It accepts two integers as input:
levelxp_to_addThere are 100 xp per level. total_xp should convert the current level to xp, then add this current xp to the xp_to_add argument and return the player's total xp. For example:
The pass keyword is a way to tell Python to do nothing. You'll need to replace it with your own code.
main_test.py file at the top of your editor. You can read the tests but you can't edit them.Focus Editor
Alt+Shift+]
Next Tab
Alt+Shift+[
Become a member to Submit
Become a member to Run
Become a member to view solution