@@ -71,3 +71,93 @@ import judge0
71
71
result = judge0.run(source_code = " print('hello, world')" )
72
72
print (result.stdout)
73
73
```
74
+
75
+ ## Examples
76
+
77
+ ### Running C Programming Language
78
+
79
+ ``` python
80
+ import judge0
81
+
82
+ source_code = """
83
+ #include <stdio.h>
84
+
85
+ int main() {
86
+ printf("hello, world\\ n");
87
+ return 0;
88
+ }
89
+ """
90
+
91
+ result = judge0.run(source_code = source_code, language = judge0.C)
92
+ print (result.stdout)
93
+ ```
94
+
95
+ ### Running Java Programming Language
96
+
97
+ ``` python
98
+ import judge0
99
+
100
+ source_code = """
101
+ public class Main {
102
+ public static void main(String[] args) {
103
+ System.out.println("hello, world");
104
+ }
105
+ }
106
+ """
107
+
108
+ result = judge0.run(source_code = source_code, language = judge0.JAVA )
109
+ print (result.stdout)
110
+ ```
111
+
112
+ ### Reading From Standard Input
113
+
114
+ ``` python
115
+ import judge0
116
+
117
+ source_code = """
118
+ #include <stdio.h>
119
+
120
+ int main() {
121
+ int a, b;
122
+ scanf("%d %d ", &a, &b);
123
+ printf("%d \\ n", a + b);
124
+
125
+ char name[10];
126
+ scanf("%s ", name);
127
+ printf("Hello, %s !\\ n", name);
128
+
129
+ return 0;
130
+ }
131
+ """
132
+
133
+ stdin = """
134
+ 3 5
135
+ Bob
136
+ """
137
+
138
+ result = judge0.run(source_code = source_code, stdin = stdin, language = judge0.C)
139
+ print (result.stdout)
140
+ ```
141
+
142
+ ### Test Cases
143
+
144
+ ``` python
145
+ import judge0
146
+
147
+ results = judge0.run(
148
+ source_code = " print(f'Hello, {input()}!')" ,
149
+ test_cases = [
150
+ (" Bob" , " Hello, Bob!" ), # Test Case #1. Tuple with first value as standard input, second value as expected output.
151
+ { # Test Case #2. Dictionary with "input" and "expected_output" keys.
152
+ " input" : " Alice" ,
153
+ " expected_output" : " Hello, Alice!"
154
+ },
155
+ [" Charlie" , " Hello, Charlie!" ], # Test Case #3. List with first value as standard input and second value as expected output.
156
+ ],
157
+ )
158
+
159
+ for i, result in enumerate (results):
160
+ print (f " --- Test Case # { i + 1 } --- " )
161
+ print (result.stdout)
162
+ print (result.status)
163
+ ```
0 commit comments