LoginSignup
1
1

More than 1 year has passed since last update.

サイコロをpythonで作ろう!(python初心者向けシリーズ①)

Last updated at Posted at 2022-10-12

python初心者向けシリーズ①
|サイコロを作ってみよう|
ーーーーーーーーーーーーー

サイコロを作るには何が必要でしょう?

1〜6(通常サイコロ)の数字と、サイコロを振ること。

数を用意するのは簡単なので…サイコロを振るのをこれで出しましょう。

import random

a = random.randint(1,6)←ここの数を変えるとサイコロの目を変えられます
aは英数字ならなにを入れても構いません。
これを関数と言います。

サイコロだけではなくおみくじを作ったり、ランダムが必要であればランダム関数を使えます。

まとめ

import random
dise = random.randint(1,6)
print("サイコロ")

random,randinはそれ以外にも
random.random() :0から1までのランダムな数値を出力する。(小数点だからね??)
random.randint(a, b) :aからbまでの間のランダムな整数を出力する
という種類があります。

それではまた別の記事でお会いしましょう。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1