2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

配列の要素をランダムに取り出す

Posted at

配列の要素をランダムに取り出すプログラムサンプルです。

# randomクラスを読み込む
import random

# 結果出力関数
def result(msg):
  print("僕の今日のおかずは" + msg + "です")

# データ配列
array1 = ["秋元真夏","長濱ねる","矢久保美緒","与田祐希","影山優佳","遠藤さくら","齋藤飛鳥"]

# 乱数を使ってランダムに配列から要素を取り出す
num = random.randint(0,len(array1)-1)
c1 = array1[num]
# 出力
result(c1)
2
3
2

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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?