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 1 year has passed since last update.

pythonでランダムで50音の一文字をテキストファイルに出力してくれるプログラムを作ろう!!

Last updated at Posted at 2021-11-27

#目的
タイトルに書いた通りの
プログラムが必要になったからです
最後の項目にいくと
コピーだけすればいいようになっているので
すぐに使いたい方は
最後だけ見てくれればいいと思います

#ファイルの出力方法
以下のサイトを参照しました

以下のようにすると
同じディレクト内に
out.txtとしてssssと書いてあるテキストファイルが作られます
aの中身を別の文字にすると別の文字がout.txtに上書きされます

f = open('out.txt', 'w')
a = "ssss"
f.write(a)
f.close()

#リスト内からランダムに一つを選ぶ
以下のサイトを参照しました

randomモジュールをimportして
stringに50音をうちこみました
こちらのプログラムを使うと
ランダムで一文字がstringに入ります

import random

japanese_list = ["","","","","",\
         "","","","","",\
         "","","","","",\
         "","","","","",\
         "","","","","",\
         "","","","","",\
         "","","","","",\
         "","","",\
         "","","","","",\
         "","",""]
string_list = random.choice(japanese_list)
string = "".join(string_list)

#さぁこれでできます!!
丸ごとコピーしてください

import random

japanese_list = ["","","","","",\
         "","","","","",\
         "","","","","",\
         "","","","","",\
         "","","","","",\
         "","","","","",\
         "","","","","",\
         "","","",\
         "","","","","",\
         "","",""]
string_list = random.choice(japanese_list)
string = "".join(string_list)

#output part
f = open('string.txt', 'w')
f.write(string)
f.close()

これでstring.txtに文字が出力されたはずです!!

0
0
3

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?