私は以前のコーディング経験のないPythonの初心者です。私はこの言語を学ぶために "絶対初心者のためのPythonプログラミング"をMike Dawsonが使用しています。割り当ての1つは - フォーチュンクッキーをシミュレートするためのプログラムで、実行するたびに5つのユニークな運勢のうちの1つをランダムに表示する必要があります。Python_Random関数を使用した変数の割り当て
私は以下のコードが、プログラムを正常に実行することができないが書かれている -
# Fortune Cookie
# Demonstrates random message generation
import random
print("\t\tFortune Cookie")
print("\t\tWelcome user!")
# fortune messages
m1 = "The earth is a school learn in it."
m2 = "Be calm when confronting an emergency crisis."
m3 = "You never hesitate to tackle the most difficult problems."
m4 = "Hard words break no bones, fine words butter no parsnips."
m5 = "Make all you can, save all you can, give all you can."
message = random.randrange(m1, m5)
print("Your today's fortune " , message)
input("\n\nPress the enter key to exit")
なぜプログラムを実行できませんか?エラーが発生していますか、起動しないか、起動しますが何もしませんか? –
おそらく 'randrange'の誤用。 user6576756はそれが魔法によって動作することを期待していました。 – wim