Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
さて、私は学んでいるので、Python を練習するための小さなゲームを書いています。この 1 週間でかなりのことを学びましたが、この特定のゲームでは困惑しています。
それはサイコロを振るゲームです(私は知っている退屈です)が、実践的な練習は良いです
私がプログラムに実行させたいのは、何人の人がプレイしているかをユーザーに尋ね、次にユーザーが入力した整数を取り、何人がプレイしているかに応じてサイコロを振ることです
3 と入力すると、サイコロを 3 回振るようになります。
これは、あなたがやろうとしていることに対してうまくいくはずです:
import random try: num_players = input("How many people are playing?") die_rolls = [] for i in range(1,num_players + 1): die_rolls.append(random.randint(1,6)) print die_rolls except: print "Error"