Python 指定した範囲の乱数を生成する

環境
Python 3.9.13
Windows 10 Home 64bit
PyCharm 2022.2.1 (Community Edition)

構文
1.randomモジュールをインポートする
import random

2.範囲を指定して乱数を生成する
random.randint(1,10)

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import random
res = random.randint(1, 10)
print("指定した範囲の乱数を生成する結果")
print(res)
import random res = random.randint(1, 10) print("指定した範囲の乱数を生成する結果") print(res)
import random

res = random.randint(1, 10)

print("指定した範囲の乱数を生成する結果")
print(res)

実行結果
指定した範囲の乱数を生成する結果
8

Python

Posted by arkgame