0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

こんにちは

pythonを習い始めたばかりのものです。
以下のプログラムで長さsで0,1,2,3を含む乱数を出力するコードを作成中です。

import numpy as np

n_one =int(input('Insert the amount of 1: '))
n_two =int(input('Insert the amount of 2: '))
n_three = int(input('Insert the amount of 3: '))
l = n_one+n_two+n_three
n_zero = l+1
s = (2*(n_zero))-1


data = [0]*n_zero + [1]*n_one + [2]*n_two + [3]*n_three
print ("Data string length is %d"  % len(data))

while data[0] == 0 and data[s-1]!=0:
         np.random.shuffle(data)
datastring = ''.join(map(str, data))
datastring = str(int(datastring))
files = open('decode.txt', 'w')
files.write(datastring)
files.write('\n')
files.close()
print("Data string is : %s " % datastring)

問題は出力の方です。
出力は0でない数字から始まって、0に終わる形にしたいです。
今のところは while分を使って、あまりうまく行かないときもあります。
なんか提案などがある人はよろしくお願いします。

0
0
1

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?