Skip to content

Commit

Permalink
Merge pull request #82 from buttonwild/main
Browse files Browse the repository at this point in the history
fix:#60 translator 1-3 code
  • Loading branch information
AmazingAng authored May 11, 2024
2 parents a38f871 + 31ff400 commit c291566
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 48 deletions.
36 changes: 14 additions & 22 deletions 01_Integer/Integer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,73 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "4b4a18e3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"加法示例: 12\n"
"Addition example: 12\n"
]
}
],
"source": [
"a, b = 7, 5\n",
"sum_result = a + b\n",
"print(f'加法示例: {sum_result}')\n"
"print(f'Addition example: {sum_result}')\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "eabe9790",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"减法示例: 2\n"
"Subtraction example: 2\n"
]
}
],
"source": [
"diff_result = a - b\n",
"print(f'减法示例: {diff_result}')\n"
"print(f'Subtraction example: {diff_result}')\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "b695268e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"乘法示例: 35\n"
"Multiplication example: 35\n"
]
}
],
"source": [
"product_result = a * b\n",
"print(f'乘法示例: {product_result}')\n"
"print(f'Multiplication example: {product_result}')\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 4,
"id": "9ff1c6e1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"除法示例: 商为 1, 余数为 2\n"
"Division example: quotient is 1, remainder is 2\n"
]
}
],
Expand All @@ -84,12 +84,12 @@
" return quotient, remainder\n",
"\n",
"quotient, remainder = euclidean_division(a, b)\n",
"print(f'除法示例: 商为 {quotient}, 余数为 {remainder}')\n"
"print(f'Division example: quotient is {quotient}, remainder is {remainder}')\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 5,
"id": "947c925c",
"metadata": {},
"outputs": [
Expand All @@ -106,14 +106,6 @@
"print(3 % -2) # 3 - (3//(-2) * -2) = -1\n",
"print(3 // -2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a1997880",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -132,7 +124,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down
18 changes: 5 additions & 13 deletions 02_Prime/Prime.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "dfb59168",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"小于等于20的质数: [2, 3, 5, 7, 11, 13, 17, 19]\n"
]
}
],
"outputs": [],
"source": [
"# Sieve of Eratosthenes\n",
"def sieve_of_eratosthenes(n):\n",
Expand All @@ -25,11 +17,11 @@
" primes[j] = False\n",
" return [x for x in range(n + 1) if primes[x]]\n",
"\n",
"# 示例:找出小于等于20的所有质数\n",
"# Example: Find all prime numbers less than or equal to 20\n",
"limit = 20\n",
"prime_numbers = sieve_of_eratosthenes(limit)\n",
"print(f'小于等于{limit}的质数: {prime_numbers}')\n",
"# 小于等于20的质数: [2, 3, 5, 7, 11, 13, 17, 19]\n"
"print(f'Prime numbers less than or equal to {limit}: {prime_numbers}')\n",
"# Prime numbers less than or equal to 20: [2, 3, 5, 7, 11, 13, 17, 19]\n"
]
},
{
Expand Down
18 changes: 5 additions & 13 deletions 03_Euclidean/Euclidean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "89bfa7da",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"30 和 24 的最大公约数是 6\n"
]
}
],
"outputs": [],
"source": [
"def euclidean_algorithm(a, b):\n",
" if a < b:\n",
Expand All @@ -22,12 +14,12 @@
" a, b = b, a % b\n",
" return a\n",
"\n",
"# 示例\n",
"# Example\n",
"num1 = 30\n",
"num2 = 24\n",
"gcd_result = euclidean_algorithm(num1, num2)\n",
"print(f'{num1} {num2} 的最大公约数是 {gcd_result}')\n",
"# 输出: 30 24 的最大公约数是 6\n"
"print(f'The greatest common divisor of {num1} and {num2} is {gcd_result}')\n",
"# Output: The greatest common divisor of 30 and 24 is 6\n"
]
}
],
Expand Down

0 comments on commit c291566

Please sign in to comment.