📋
Auto-Grading for Teachers
  • Learn How to Auto-Grade
  • Assertions and Unit Testing
  • Request / Submit Examples
  • 🐍Python Examples
    • Check Variable Values
    • Output Tests
    • Input / Output Tests
    • Print Function Tests
    • Return Function Tests
    • Random Number Tests
    • Parse Student Code
  • ☕Java Examples
    • Check Variable Values
    • Output Tests
    • Input / Output Tests
    • Return Method Tests
    • Class - .toString() and Void Method Tests
    • Random Numbers Tests
    • Array and ArrayList Tests
    • Parse Student Code
  • 💎Ruby Examples
    • Output Tests
    • Input / Output Tests
    • Print Function Tests
    • Return Function Tests
    • Parse Student Code
Powered by GitBook
On this page
  • Simple variable value
  • Number of items in a list

Was this helpful?

Export as PDF
  1. Python Examples

Check Variable Values

Simple variable value

To check a variable value you need to import the student's code and use dot notation to get the value.

Example, maybe you ask students to assign a variable named num1 the value of 5.

Student Code:

example.py
num1 = 5

Grading Tests:

import unittest

class CodingRoomsUnitTests(unittest.TestCase):

    def test_default_case(self):
        import example
        self.assertTrue(example.num1 == 5)

if __name__ == '__main__':
    unittest.main()

Number of items in a list

You can do anything you need to with a student's variable value. For example, we can see if a student created a list with at least 3 items using the len() function.

Student Code:

example.py
my_list = ["first thing", "second thing", "third thing"]

Grading Tests:

import unittest

class CodingRoomsUnitTests(unittest.TestCase):

    def test_default_case(self):
        import example
        self.assertTrue( len(example.my_list) >= 3 )

if __name__ == '__main__':
    unittest.main()

PreviousRequest / Submit ExamplesNextOutput Tests

Last updated 3 years ago

Was this helpful?

🐍