Skip to content

Commit

Permalink
feat: add more detailed python test code
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-Addict committed Feb 18, 2024
1 parent 0f42076 commit 5e51221
Show file tree
Hide file tree
Showing 10 changed files with 489 additions and 53 deletions.
38 changes: 19 additions & 19 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/example/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ expand = true
heading-split-level = 3
copy-js = true

[output.markdown]

[preprocessor.repl]
command = "target/release/mdbook-repl"
10 changes: 9 additions & 1 deletion backend/example/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Summary

- [Intro](./intro.md)
- [Intro](intro.md)
- [Python](python/intro.md)
- [Get Started](python/get-started.md)
- [Basics](python/basics.md)
- [Variable and Types](python/variable-and-types.md)
- [Operators](python/operators.md)
- [C]()
- [C++]()
- [Javascript]()
17 changes: 7 additions & 10 deletions backend/example/src/intro.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# Mdbook REPL

This is a python **realtime** playground which uses pyodide **webassembly** to run python code in the browser. So you can run python code in the browser without any server.
This is a [mdbook](https://rust-lang.github.io/mdBook) playground which uses **webassembly** to execute code in the browser. So you can run code in the browser without any server.

Below is a simple example, you can run the code and see the output.
This is inspired by mdbook rust playground, but it is not limited to rust. Nowdays, webassembly is very powerful, so I learned it and try to make a playground for multiple languages with mdbook.

**Python**
Now only **Python** is supported, maybe I will add more languages in the future.

```python
# This is a default python code
import calendar
# Python

yy = 2024 # year
mm = 2 # month

# display the calendar
print(calendar.month(yy, mm))
print("Hello, World!")
```

Tell me if you have any ideas or suggestions.
35 changes: 35 additions & 0 deletions backend/example/src/python/basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Basics

## encode

By default, Python source files are encoded in **UTF-8** and all strings are unicode strings. Of course, you can also specify different encodings for the source code files:

```plaintext
# -*- coding: cp-1252 -*-
```

The above definition allows the use of character encoding from the Windows-1252 character set in the source file, corresponding to Bulgarian, Belarusian, Macedonian, Russian, Serbian.

## comments

Python uses the hash character `#` to start a comment. The comment ends at the end of the line.

```python
# This is a comment

print("Hello, World!") # This is also a comment
```

## multi-line comments

Python does not have a syntax for multi-line comments, but you can use triple quotes:

```python
"""
This is a comment
written in
more than just one line
"""

print("Hello, World!")
```
25 changes: 25 additions & 0 deletions backend/example/src/python/get-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Get Started

## Who should read this tutorial?

This tutorial is for developers who want to learn the Python programming language from scratch. Of course, this tutorial will also provide some in-depth modules to give you a better understanding of Python applications.

## The first Python program

For most programming languages, the first code to get started is "Hello World!", and the following code is to output "Hello World!" in Python:

```python
# Python

print("Hello, World!")
```

A common Python file extension is .py.

You can save the above code in a hello.py file and execute the script file with python commands.

```bash
python hello.py
```

You should see the output "Hello, World!" in the terminal or you can run the code in the browser by clicking the **Play** button below.
13 changes: 13 additions & 0 deletions backend/example/src/python/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Python

Python is a widely used high-level programming language for general-purpose programming, created by Guido van Rossum and first released in 1991.

Python features a dynamic type system and automatic memory management and supports multiple programming paradigms, including object-oriented, imperative, functional programming, and procedural styles. It has a large and comprehensive standard library.

You can learn some basics of Python in the following sections.

```python
# Python

print("Hello, World!")
```
Loading

0 comments on commit 5e51221

Please sign in to comment.