現在、クラスのヒストグラムを作成しようとしています。私はこれを2ヶ月間しかやっていないので私のスキルを発達させています。これは専門家のためのウェブサイトであると分かっています。
def histo_print(times, dicerand, symbol='*'):
print('%ds: %s' % (times, (dicerand * symbol)))
質問:
は "シンボル" のデフォルトとして文字列を使用することが可能ですか?
デフォルトの文字列文字をループの外側の "シンボル"変数に割り当てると、より良いでしょうか?次に、割り当てた後に入力関数を配置しますか?
これまでの質問と同じような質問はありませんでした。 誰でもこの質問に答えられていることが分かっている場合は、というURLを投稿してください。しかし、私は仕上げの時間があまりありません。ご協力いただきありがとうございます。
これは、全体のコードです:
def histo_print(times,dicerand,symbol):
if symbol == none
print ('%ds: %s' % (times,(dicerand * symbol)))
def rand(user_input):
number = 0
while number != user_input:
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
roll_total = die1 + die2
return roll_total
"""Introduction"""
print('Welcome to the Dice roll histogram.')
if num_rolls >= 1:
"""Adds one to user input because the for loop starts at one."""
num_rolls += 1
"""Optional Secondary input based on if the number entered is greater than zero."""
character = str(input('Please enter character:\n')) # Additional input for user choice.
"""Unnecessary, just looks nice."""
print('Dice roll histogram:\n')
for i in range(1,num_rolls):
rand(num_rolls)
#Output
histo_print(i, rand(num_rolls),character)
else:
print('Invalid number of rolls. Try again.')
あなたはどんなループについて話していますか?私が使用しています – polku
@polkuループ---範囲のiについて (1、num_rolls) "のための": ランド(num_rolls) #Output histo_print(I、ランド(num_rolls)、文字) –
ポスト関数が呼び出された場所からコードを取り出し、希望する出力を提供してください。ウェブサイトは専門家のためだけではありません。 –