Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

Python while true loops

I have this code:

Roll=[1,2,4]
for h in Roll:
    if set(Roll)=={4,5,6}:
        print('Automatic win! Banker wins all bets! Round ends!')
        break
    elif len(set(Roll))==2 and Roll.count(h)==2:
        Roll.remove(h)
        Roll.remove(h)
        if Roll[0]==1:
            print('Banker lost')
        elif Roll[0]==2:
            banker_score=Roll[0]
            print('Banker scored ',banker_score)
        elif Roll[0]==3:
            banker_score=Roll[0]
            print('Banker scored ',banker_score)
        elif Roll[0]==4:
            banker_score=Roll[0]
            print('Banker scored ',banker_score)
        elif Roll[0]==5:
            banker_score=Roll[0]
            print('Banker scored ',banker_score)
        elif Roll[0]==6:
            print('Automatic win! Banker wins all bets! Round ends!')
    elif set(Roll)=={1,2,3}:
        print('Banker lost')
        break
    elif Roll[0]==Roll[1]==Roll[2]:
        print('Automatic win! Banker wins all bets! Round ends!')
        break

*This code is part of a bigger code so the list elements(here they are stable),change because i want to check if my code works.Till this point my code works fine but i have 1 problem.If the combination of the list elements isnt in one of the if,elif the code should re-run the whole process printing Banker rolls again.My question is: will a while true loop help me here?

question from:https://stackoverflow.com/questions/65599234/python-while-true-loops

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...