0

以下のPythonのループに問題があります。

totalout = 4になるとすぐに停止しませんが、scoreinのループ全体が終了した場合にのみ停止します。(つまり、3番目のループ)

たとえば、スコアイン番号2のtotalout = 4の場合、10に達するまでループを実行します。

#global value   
totalturn=0
totalscorein=0
totalout=0

def main

  numberofturn=int(input("Number of score:"))

  no_turn=['1','2','3','4','5','6','7','8','9','10'] 
    #while loop condition    
    while totalturn<numberofturn and totalout<10:

            #increasement
            totalscore+=1

            #for loop for score
            for t in range(1,numberofturn+1):
                turns=s*1

                print("\n\n\nThe turn"+no_turn[t]+":",turns)

                #for loop for number to appear from list
                for c in range (10):

                    #list for random number to appear
                    numscore = ['1','2','3','4','5','6','7','8','9','o']

                    #random choice from numscore list to appear
                    from random import choice
                    scorein=choice(numscore)

                    print ("\n\nScores :",scorein)




                    if scorein.isdigit():
                        totalscorein=totalscorein+int(scorein)               


                    if scorein.isalpha():
                        totalout+=1



                    if totalturn==numberofturn:
                        print("\nTotal turn played:",totalturn)


                    elif totalout==4:

                        print("\nTotal turns played",totalturn)
                        break

                    else:

                        print("")
4

2 に答える 2

1

breakを 3 つのループから抜け出しますか? 質問のタイトルから察するに

この場合、関数の最後なので、次のように置き換えるだけですbreakreturn

于 2012-04-26T10:13:19.153 に答える
0

and演算子を に変更してみてくださいor。それがあなたの望みのようです。

while totalscore<numberofscore or totalout<10:

于 2012-04-26T09:59:04.660 に答える