LoginSignup
1
0

More than 5 years have passed since last update.

pythonであみだくじもどきを作ってみた。

Posted at

前述

会社の飲み会で幹事を決める際に、あみだくじを使用しました。
なかなかいいサイトが見当たらないので、自作を試みましたが線を引くのとか面倒。
なので、単純にスタートの数配列を用意して、それをランダムに入れ替えたものをゴールに設定し、1に行く人が当たりにしました。

これも
無題.png

これも
無題.png

結果は変わらないので。

環境

  • CentOS7.5
  • Python 3.6.5

プログラム

#!/bin/python
# -*- coding: utf-8 -*-

import random

def main() :
    while True :

        print('input number')
        number = input('>>')
        if not number.isdigit() :
            print('wrong number')
            continue

        list = []
        target = []
        for choice in range(1, int(number)+1) :
            list.append(choice)
            print('input name')
            target_name = input('>>')
            target.append(target_name)

        print(list)
        goal_list = random.sample(list, len(list))
        print(goal_list)
        index = goal_list.index(1)
        print("%sさんがあたりです。" % target[index])

        break

if __name__ == "__main__":
    main()

使用例

python3.6 test.py
input number
>>4
input name
>>a
input name
>>b
input name
>>c
input name
>>d
[1, 2, 3, 4]
[4, 1, 2, 3]
bさんがあたりです。
1
0
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
1
0