質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
リストボックス

ユーザーがリストから1つ以上のアイテムを選択できるようにするGUI要素です。

ループ

ループとは、プログラミングにおいて、条件に合致している間、複数回繰り返し実行される箇所や、その制御構造を指します

コードレビュー

コードレビューは、ソフトウェア開発の一工程で、 ソースコードの検査を行い、開発工程で見過ごされた誤りを検出する事で、 ソフトウェア品質を高めるためのものです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

797閲覧

Pythonリストを使って関数を呼びだす方法について

Spursfun2002

総合スコア15

リストボックス

ユーザーがリストから1つ以上のアイテムを選択できるようにするGUI要素です。

ループ

ループとは、プログラミングにおいて、条件に合致している間、複数回繰り返し実行される箇所や、その制御構造を指します

コードレビュー

コードレビューは、ソフトウェア開発の一工程で、 ソースコードの検査を行い、開発工程で見過ごされた誤りを検出する事で、 ソフトウェア品質を高めるためのものです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

1グッド

1クリップ

投稿2020/05/09 22:46

編集2020/05/10 00:24

これが各メゾットに対してやらなければいけないことです。僕自身はこれをすべてクリアしているつもりです(おかしい場所があったら言ってくれるとありがたいです。)
最後のところで僕はForループを使いroll_diceとupdate_listを呼び出しサイコロを振らないといけないのですがどうやればいいのでしょうか?

import random roll_list = [] #holds the number of times each number was rolled # has 13 spots (0 - 12). roll_list[1] is how many times # a 1 was rolled. num_rolls = 100 # number of times to roll the dice # initialize the roll_list[] so it has the correct number of spots def init_list(): for x in range(13): list.append(x) return init_list() # use a for loop and list.append( x ) to fill the roll_list with 13 zeros # returns the sum of the two dice that were rolled def roll_dice(): for x in range: twodice = random_randint(1, 6) + random_randint(1, 6) rolls.append(twodice) return roll_dice() # roll 2 standard die and return the sum (should be from 2 to 12) # random.randint() will be helpful here # change this line so it returns the correct sum def update_list( roll ): for x in roll_list: if x == roll_list: return x+1 return update_list() # add 1 to the list location associated with the total roll value # example: if the total of the roll is 7, then add 1 to roll_list[7] def print_histogram(): maxBar = str(13) for x in roll_list: p = str(x) if p <= maxBar: p += '*' return print_histogram() # for 100% create and print a histogram of the results of all # of the dice rolls # sample output: """ 0: 1: 2: *** 3: ****** 4: *************** 5: ************ 6: ************ 7: ************ 8: *********** 9: *********** 10: *********** 11: **** 12: *** """ # main program init_list() for x in roll_list: x = roll_dice() print(x) for i in roll_list: i = update_list() print(x) # make a for loop that calls both roll_dice() and update_list() to roll the dice # and update the list based on that result. The loop should repeat the number # of times the die are to be rolled. # for a 90%, print the final list here # for a 100% complete print_histogram() and call it here

これどうすればいいんですかね。

この部分にエラーがでました。

for x in roll_list: x = roll_dice() print(x) for i in roll_list: i = update_list() print(x)

エラーは次のとおりです。

Traceback (most recent call last): File "python", line 37 for x in roll_list: ^ IndentationError: unexpected indent

エラーを改善することができました。

DrqYuto👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

1.def print_histogram():
インデントがおかしいので見直してみてください。

2.roll_dice()
twodice = random.randint(1, 6) + random.randint(1, 6)
random_randint()では動作しません。

3.roll_dice()
rolls.append(twodice)
rollsはどこから?

投稿2020/05/09 23:58

編集2020/05/10 00:01
yodel

総合スコア508

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Spursfun2002

2020/05/10 00:30

見やすいように説明していただきありがとうございます。 1, 改善することができたんですが、 2, random.randint()以外でなにをつかえばいいのでしょうか? 3,ほんとですね、どこから来たのでしょう。多分凡ミスです。すいません。Appendコードはどうやれば使えるようになりますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問