简体   繁体   English

需要帮助来修复我的列表条件语句

[英]Need help to fix my list conditional statement

i want it to go through the conditions but it tends to get them wrong and i cant figure out how to fix it.我希望通过条件将其设置为 go,但它往往会出错,我无法弄清楚如何解决它。 it goes through some of them and then makes two of them pop up as if they are right when they are actually wrong它通过其中一些,然后使其中两个弹出,好像它们是正确的,但实际上它们是错误的

OUTCOME = ['Player wins', 'Banker wins', 'Tie']
bet_choices = input("Place your bet, Banker or Player, also you can bet the tie: ").title()

if 'Player wins' in OUTCOME and bet_choices == 'Player':
    bet_money = bet_amount * 2 + bet_money

    print("You won,Your total is now " + str(bet_money))
elif 'Player wins' in OUTCOME and bet_choices == 'Banker':
    print("You bet Banker,and you lost so your total is " + str(bet_money))

elif 'Banker wins' in OUTCOME and bet_choices == 'Banker':
    bet_money = bet_amount * 2 + bet_money
    print("You won,Your total is now " + str(bet_money))

elif 'Banker wins' in OUTCOME and bet_choices == 'Player':
    print("You bet Banker,and you lost so your total is " + str(bet_money))

elif 'Tie' in OUTCOME and ate_to_1 == 'Yes':
    bet_money += tie_amount * 8
    print("Your total is now after betting on the tie " + str(bet_money))

i wanted to match up the users bet with the results of the game and if they get the right guess then they win money and if they dont then they lose money.我想将用户的赌注与游戏结果相匹配,如果他们猜对了,他们就会赢钱,如果他们没有猜对,他们就会输钱。 Its suppose to go through all the conditions and its not它假设通过所有条件为 go 而不是

the 'player_hand' and 'Banker_hand is randomized 'player_hand' 和 'Banker_hand 是随机的

i want this:我要这个:

bet = 50
userbet = Player
player_hand = 4 5 = 9
banker_hand = 4 4 = 8

player won and You won 100

Your OUTCOME is a List.你的结果是一个列表。
It has Not been altered anywhere in the provided code, hence constant.它在提供的代码中的任何地方都没有改变,因此是不变的。

Therefore, All Your first sections of IF statements will ALWAYS return TRUE.因此,您所有的 IF 语句的第一部分将始终返回 TRUE。
ie IE
since 'Player wins', 'Banker wins', 'Tie' are all in OUTCOME.因为“闲赢”、“庄赢”、“平局”都在结果中。

In essence, only the Second part of Your IF statements Decides the Flow.本质上,只有 IF 语句的第二部分决定流程。
ie IE

and bet_choices == 'Player':  
and bet_choices == 'Banker':  
and bet_choices == 'Banker':  
and bet_choices == 'Player':  
and ate_to_1 == 'Yes':  

Hence the First and the Fourth condition are literally the same/duplicate.因此,第一个和第四个条件实际上是相同的/重复的。 (Player) (玩家)
Just as the Second and the Third.就像第二个和第三个一样。 (Banker) (银行家)

EXAMPLE:例子:
Assuming you are using 'Banker wins' and bet_choices == 'Player' , the code will check the first IF statement假设您使用的是'Banker wins'bet_choices == 'Player' ,代码将检查第一个 IF 语句
ie IE
if 'Player wins' in OUTCOME . if 'Player wins' in OUTCOME This will evaluate to TRUE.这将评估为 TRUE。
Then it will check the and Part of that first statement;然后它将检查第一条语句的and部分; ie IE
and bet_choices == 'Player': , this too will evaluate to TRUE. and bet_choices == 'Player': ,这也将评估为 TRUE。
Thus the code in the First statement will be executed.因此,将执行 First 语句中的代码。
The 3rd and 4th statements will NEVER be Used in Your Case.第 3 和第 4 个陈述将永远不会在您的案例中使用。 Only Your 1st, 2nd and last statements make decisions in Your code.只有您的第一个、第二个和最后一个语句在您的代码中做出决定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM