2016-10-17 4 views
-3

私はスクリプトを自動的に再起動したいのですが、私はサイコロのスクリプトを使用しています。python dice rolling restartスクリプト

import random 
from random import randrange 
from random import randint 
r = randint 
min = 1 
max = 6 

rolls = int(float(input('how menny times do you want to roll:'))) 

for x in range(rolls): 
    print ('Rolling the dices...') 
    print ('The value is....') 
    print (r(min, max)) 

私はそれを行うにはいくつかの方法を試してみましたが、それらのどれもが、私はあなたが実際にやろうとしたが、ここで私はその意志を書いたプログラムが何であるかを100%わからない

+1

あなたはどのような方法で試してみましたか、正確には動作しませんでしたか? FYI、 '' menny '!=' many''。 – jonrsharpe

+0

あなたは 'whileループ 'に読み込むように聞こえます – MooingRawr

+0

単純な' whileループ 'はすべきです。 –

答えて

0

を働いていませんロール2は一度に死にますが、ロールしたいロールを多く生成します。再帰的な(main main自体はメインから呼び出す)ベストプラクティスではありませんが、これは何かこの基本的な問題ではありません。

※Python 3以降を使用している場合は、raw_inputを入力と置き換えてください。私はraw_inputを使用するので、私は2.7を使用します

import time 
import random 

def roll_multiple(): 
#honestly this is all you need to do what you want to do, the rest just turns it into a game and allows multiple runs 
    roll_number = int(raw_input("How Many Times Would You Like to Roll?\n")) 
    for i in range(roll_number): 
     print"You Rolled A ", random.randrange(1,6,1), " and a ", random.randrange(1,6,1) 
#that's it! if you do these 3 lines, it will ask for how many times, and for each item in range of roll_number (whatever you input) it will run the print below and generate new numbers for each roll. 

def main(): 
    print("Welcome to Craps 2.0") 
    playing = raw_input("Press Enter to Roll or Q to quit") 

    if playing == 'q': 
     print("Thanks for Playing") 
     time.sleep(2) 
     quit() 
    elif playing != 'q': 
     roll_multiple() 
     main() 
main() 
+0

これは私のPythonのバージョンで動作するように編集してあり、完璧に動作します。 – Alex