MjRmYjQ2YWJmYmVkNjA5NzQyZmU3NDljNWVhZmEyYzc0YWY5Yjk5YzhiY2Y2NWE3YTc4OGNhYzMzMjRmMzlhZA.msfhdqof.eyJ1cmwiOiIvcGwvY291cnNlX2luc3RhbmNlLzIvaW5zdGFuY2VfcXVlc3Rpb24vMjAzLyIsImF1dGhuX3VzZXJfaWQiOiIxIn0
Skip to main content Accessibility guide
PrairieLearn Go home
  • XC 101, SectionA
  • Assessments
  • Gradebook
  • C4
Load from disk
  • Dev User student
    View type
    ✓ Staff view staff ✓ Student view student ✓ Student view without access restrictions student
    Effective user
    Customize…
    Course Requests Settings Log out

Regenerate assessment instance

Warning: Regenerating the assessment instance will select a new set of questions from this assessment. Any progress on the current assessment instance will be lost.

Are you sure you want to regenerate the assessment instance?

Course staff: Regenerate your assessment instance to pick up changes to the assessment or to get a fresh set of questions.

C4.30. Element pl-python-variable: Display of Python variables

The following examples below were created to show the capabilities of the pl-python-variable element, which allows formatting and rendering various Python variables defined in the server.py on a question page. The semantics of this element are very similar to those of the Python pprint library, and we encourage reviewing documentation for that library for more detailed examples.

These examples are drawn from the pprint library documentation and a tutorial for using this library.

Here is a randomly generated matrix created by calling np.random.random((3, 3)). Any variables will be converted using repr() if they are being shown as text.

1
2
3
array([[0.59519245, 0.82867175, 0.11360416],
       [0.21737209, 0.62686544, 0.77399563],
       [0.8758432 , 0.29719525, 0.58382573]])

Here is an example displaying a dictionary. You can add additional text to the output by using the prefix and suffix attributes. We also set copy-code-button="True" to enable the copy code button.

1
my_dictionary = {'a': 1, 'b': 2, 'c': 3}

Here is an example displaying a string.

1
my_string = 'a string'

Here is an example displaying a dictionary with line breaks. We've set width="1" to force printing each element on a new line and set prefix-newline="true" to insert a line break between the prefix and the printed dictionary.

1
2
3
4
my_dictionary = \
{'a': 1,
 'b': 2,
 'c': 3}

Here is an example displaying a list with line breaks and a comment on the next line using the suffix and suffix-newline attributes.

1
2
3
4
5
my_list = \
['a',
 'b',
 'c']
# This is a cool list

Here is an example displaying a more complex list. We've also enabled line numbers by setting show-line-numbers="True", and compact sequences by setting compact-sequences="True".

1
2
[{'a': 1, 'aa': 1}, {'b': 2, 'bb': 2},
 {'c': 3, 'cc': 3}, {'d': 4, 'dd': 4}]

Here is an example displaying a list with indent="4".

1
2
3
4
5
6
[   ['spam', 'eggs', 'lumberjack', 'knights', 'ni'],
    'spam',
    'eggs',
    'lumberjack',
    'knights',
    'ni']

Here is an example displaying a complex dictionary with depth="3", to limit the depth of the data structures that are displayed, and indent="4", to provide some space between levels .

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
[   {   'id': 1,
        'name': 'Leanne Graham',
        'email': 'Sincere@april.biz',
        'phone': '1-770-736-8031 x56442',
        'address': {   'geo': {...},
                       'city': 'Gwenborough',
                       'suite': 'Apt. 556',
                       'street': 'Kulas Light',
                       'zipcode': '92998-3874'},
        'company': {   'bs': 'harness real-time e-markets',
                       'name': 'Romaguera-Crona',
                       'catchPhrase': 'Multi-layered client-server neural-net'},
        'website': 'hildegard.org',
        'username': 'Bret'},
    {   'id': 2,
        'name': 'Ervin Howell',
        'email': 'Shanna@melissa.tv',
        'phone': '010-692-6593 x09125',
        'address': {   'geo': {...},
                       'city': 'Wisokyburgh',
                       'suite': 'Suite 879',
                       'street': 'Victor Plains',
                       'zipcode': '90566-7771'},
        'company': {   'bs': 'synergize scalable supply-chains',
                       'name': 'Deckow-Crist',
                       'catchPhrase': 'Proactive didactic contingency'},
        'website': 'anastasia.net',
        'username': 'Antonette'},
    {   'id': 3,
        'name': 'Clementine Bauch',
        'email': 'Nathan@yesenia.net',
        'phone': '1-463-123-4447',
        'address': {   'geo': {...},
                       'city': 'McKenziehaven',
                       'suite': 'Suite 847',
                       'street': 'Douglas Extension',
                       'zipcode': '59590-4157'},
        'company': {   'bs': 'e-enable strategic applications',
                       'name': 'Romaguera-Jacobson',
                       'catchPhrase': 'Face to face bifurcated interface'},
        'website': 'ramiro.info',
        'username': 'Samantha'},
    {   'id': 4,
        'name': 'Patricia Lebsack',
        'email': 'Julianne.OConner@kory.org',
        'phone': '493-170-9623 x156',
        'address': {   'geo': {...},
                       'city': 'South Elvis',
                       'suite': 'Apt. 692',
                       'street': 'Hoeger Mall',
                       'zipcode': '53919-4257'},
        'company': {   'bs': 'transition cutting-edge web services',
                       'name': 'Robel-Corkery',
                       'catchPhrase': 'Multi-tiered zero tolerance '
                                      'productivity'},
        'website': 'kale.biz',
        'username': 'Karianne'},
    {   'id': 5,
        'name': 'Chelsey Dietrich',
        'email': 'Lucio_Hettinger@annie.ca',
        'phone': '(254)954-1289',
        'address': {   'geo': {...},
                       'city': 'Roscoeview',
                       'suite': 'Suite 351',
                       'street': 'Skiles Walks',
                       'zipcode': '33263'},
        'company': {   'bs': 'revolutionize end-to-end systems',
                       'name': 'Keebler LLC',
                       'catchPhrase': 'User-centric fault-tolerant solution'},
        'website': 'demarco.info',
        'username': 'Kamren'},
    {   'id': 6,
        'name': 'Mrs. Dennis Schulist',
        'email': 'Karley_Dach@jasper.info',
        'phone': '1-477-935-8478 x6430',
        'address': {   'geo': {...},
                       'city': 'South Christy',
                       'suite': 'Apt. 950',
                       'street': 'Norberto Crossing',
                       'zipcode': '23505-1337'},
        'company': {   'bs': 'e-enable innovative applications',
                       'name': 'Considine-Lockman',
                       'catchPhrase': 'Synchronised bottom-line interface'},
        'website': 'ola.org',
        'username': 'Leopoldo_Corkery'},
    {   'id': 7,
        'name': 'Kurtis Weissnat',
        'email': 'Telly.Hoeger@billy.biz',
        'phone': '210.067.6132',
        'address': {   'geo': {...},
                       'city': 'Howemouth',
                       'suite': 'Suite 280',
                       'street': 'Rex Trail',
                       'zipcode': '58804-1099'},
        'company': {   'bs': 'generate enterprise e-tailers',
                       'name': 'Johns Group',
                       'catchPhrase': 'Configurable multimedia task-force'},
        'website': 'elvis.io',
        'username': 'Elwyn.Skiles'},
    {   'id': 8,
        'name': 'Nicholas Runolfsdottir V',
        'email': 'Sherwood@rosamond.me',
        'phone': '586.493.6943 x140',
        'address': {   'geo': {...},
                       'city': 'Aliyaview',
                       'suite': 'Suite 729',
                       'street': 'Ellsworth Summit',
                       'zipcode': '45169'},
        'company': {   'bs': 'e-enable extensible e-tailers',
                       'name': 'Abernathy Group',
                       'catchPhrase': 'Implemented secondary concept'},
        'website': 'jacynthe.com',
        'username': 'Maxime_Nienow'},
    {   'id': 9,
        'name': 'Glenna Reichert',
        'email': 'Chaim_McDermott@dana.io',
        'phone': '(775)976-6794 x41206',
        'address': {   'geo': {...},
                       'city': 'Bartholomebury',
                       'suite': 'Suite 449',
                       'street': 'Dayna Park',
                       'zipcode': '76495-3109'},
        'company': {   'bs': 'aggregate real-time technologies',
                       'name': 'Yost and Sons',
                       'catchPhrase': 'Switchable contextually-based project'},
        'website': 'conrad.com',
        'username': 'Delphine'},
    {   'id': 10,
        'name': 'Clementina DuBuque',
        'email': 'Rey.Padberg@karina.biz',
        'phone': '024-648-3804',
        'address': {   'geo': {...},
                       'city': 'Lebsackbury',
                       'suite': 'Suite 198',
                       'street': 'Kattie Turnpike',
                       'zipcode': '31428-2261'},
        'company': {   'bs': 'target end-to-end models',
                       'name': 'Hoeger LLC',
                       'catchPhrase': 'Centralized empowering task-force'},
        'website': 'ambrose.net',
        'username': 'Moriah.Stanton'}]
Additional attempts available with new variants

Correct answer

Collection 4

Assessment overview
Total points: 0/360
Score:
0%

Question C4.30

Value: 2
All variants: Open (current)
Total points: — /10
Auto-graded question

This form is only for reporting errors in the question itself. Do not use this form if you just don't know how to answer the question.

Previous question Next question

 Personal Notes

No attached notes

Attached files will be saved here for your reference. These files act as personal notes and can be used for your own review purposes. They are not used for grading.

Max file size: 10 MB

Attached personal notes will be saved here for your reference. These notes can be used for your own review purposes. They are not used for grading.

Staff information

Student details

Dev User
dev@example.com

Question

QID:
element/pythonVariable
Title:
Element pl-python-variable: Display of Python variables

Variant

Started at:
2026-08-04 16:38:12 (CDT)
Duration:
0s
Show/Hide answer
{}

Assessment instance

Assessment:
gallery/elements
Started at:
2026-08-04 16:37:17 (CDT)
Duration:
0s
View log
This box is not visible to students.