Files
Ikko Eltociear Ashimine 954c45864b docs: add Japanese translate documents (#1812)
* docs: add Japanese documents (`ja/docs`)

* docs: add Japanese documents (`ja/codes`)

* docs: add Japanese documents

* Remove pythontutor blocks in ja/

* Add an empty at the end of each markdown file.

* Add the missing figures (use the English version temporarily).

* Add index.md for Japanese version.

* Add index.html for Japanese version.

* Add missing index.assets

* Fix backtracking_algorithm.md for Japanese version.

* Add avatar_eltociear.jpg. Fix image links on the Japanese landing page.

* Add the Japanese banner.

---------

Co-authored-by: krahets <krahets@163.com>
2025-10-17 05:04:43 +08:00

65 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
File: iteration.py
Created Time: 2023-08-24
Author: krahets (krahets@163.com)
"""
def for_loop(n: int) -> int:
"""forループ"""
res = 0
# 1, 2, ..., n-1, n の合計をループ
for i in range(1, n + 1):
res += i
return res
def while_loop(n: int) -> int:
"""whileループ"""
res = 0
i = 1 # 条件変数を初期化
# 1, 2, ..., n-1, n の合計をループ
while i <= n:
res += i
i += 1 # 条件変数を更新
return res
def while_loop_ii(n: int) -> int:
"""whileループ2つの更新"""
res = 0
i = 1 # 条件変数を初期化
# 1, 4, 10, ... の合計をループ
while i <= n:
res += i
# 条件変数を更新
i += 1
i *= 2
return res
def nested_for_loop(n: int) -> str:
"""二重forループ"""
res = ""
# i = 1, 2, ..., n-1, n をループ
for i in range(1, n + 1):
# j = 1, 2, ..., n-1, n をループ
for j in range(1, n + 1):
res += f"({i}, {j}), "
return res
"""Driver Code"""
if __name__ == "__main__":
n = 5
res = for_loop(n)
print(f"\nforループの合計結果 res = {res}")
res = while_loop(n)
print(f"\nwhileループの合計結果 res = {res}")
res = while_loop_ii(n)
print(f"\nwhileループ2つの更新の合計結果 res = {res}")
res = nested_for_loop(n)
print(f"\n二重forループの走査結果 {res}")