Skip to content

Commit 0bf66d0

Browse files
committed
revise C++ example
1 parent 9bba733 commit 0bf66d0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Python/Module1_GettingStartedWithPython/GettingStartedWithPython.ipynb

+9-7
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,21 @@
116116
"source": [
117117
"## Why Python?\n",
118118
"\n",
119-
"Python has become a hugely popular programming language. In fact, it is likely the [most popular introductory language at universities](https://cacm.acm.org/blogs/blog-cacm/176450-python-is-now-the-most-popular-introductory-teaching-language-at-top-u-s-universities/fulltext). First and foremost, its syntax is designed to be intuitive and readable. For example, the following Python code:\n",
119+
"Python has become a hugely popular programming language. In fact, it is likely the [most popular introductory language at universities](https://cacm.acm.org/blogs/blog-cacm/176450-python-is-now-the-most-popular-introductory-teaching-language-at-top-u-s-universities/fulltext). First and foremost, its syntax is designed to be intuitive and readable. For example, the following Python code sums the numbers 0-9, and prints the result:\n",
120120
"```python\n",
121-
"print(\"Hello world\")\n",
121+
"a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
122+
"print(sum(a))\n",
122123
"```\n",
123124
"\n",
124-
"produces the same result as the less-obvious and lengthier C++ code:\n",
125+
"This can be reproduced by the following C++ code, which is arguably less-intuitive:\n",
125126
"```cpp\n",
126127
"#include <iostream>\n",
128+
"#include <vector>\n",
129+
"#include <numeric>\n",
127130
"\n",
128-
"int main()\n",
129-
"{\n",
130-
" std::cout << \"Hello world\" << std::endl;\n",
131-
" return 0;\n",
131+
"int main() {\n",
132+
" std::vector<int> a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};\n",
133+
" std::cout << std::accumulate(a.begin(), e.end(), 0) << std::endl;\n",
132134
"}\n",
133135
"```\n",
134136
"\n",

0 commit comments

Comments
 (0)