尝试创建具有两次掷骰和返回值的骰子模拟游戏

Trying to create a dice simulation game with two rolls and a returned value

我正在设计一个调用随机掷骰子函数的函数。如果两个数字都猜对了,钱就会翻三倍。如果不是,钱就会丢失。如果是,掷骰子的总和就是失败的目标。如果您在掷出 guess1 或 guess2 之前掷出失败的目标,您就输了,如果没有,您就赢了,并且您的钱翻倍...

我正在努力做到掷骰子的顺序无关紧要,也不会重复计算数字。

我也在为失去目标的情况而努力制作一个while循环......请帮忙!对此很陌生。

def play(guess1:int,guess2:int, dollars:int):
    
    random_die1 = roll_one_die() ##calling helper function 
    random_die2 = roll_one_die() 
    win_count = 0 ## these are not correct, not sure how to properly account for different rolls
    if guess1 == random_die1:
        win_count = 1
    else:
        win_count = 0
    
    if guess1 == random_die2:
        if win_count==1:
            win_count = 1
        else:
            win_count = 1
               
    if guess2 == random_die1:
        if guess1 != random_die1 and guess1 != random_die2:
            win_count+= 1
    else:
        win_count += 0
    if guess2 == random_die2:
        if guess2 != random_die1 and guess2 != random_die2:
            win_count+= 1
        #if win_count==2:
            #win_count=2
        else:
            win_count +=0 

    if win_count ==2:
        dollars=dollars*3
    elif win_count ==0:
        dollars=0
    else:
        losing_target= random_die1+random_die2
        new_roll1 = roll_one_die()
        new_roll2 = roll_one_die()
        sum_of = (new_roll1 + new_roll2)
        if losing_target==sum_of:
            dollars==0        
        while sum_of!= losing_target: ## not sure how to properly loop so first situation = win or loss
            sum_of == new_roll1 + new_roll2
            if new_roll1 == guess1 or new_roll1 == guess2 or new_roll2 == guess1 or new_roll2 == guess2:
                dollars=dollars*2
        return(dollars)

我不愿意 post 一个完整的解决方案,因为我相信你最好自己解决这个问题。

对于丢失目标的情况,肯定需要在while循环中掷骰子,例如

while True:
    new_roll1 = roll_one_die()
    new_roll2 = roll_one_die()
    sum_of = new_roll1 + new_roll2
    if losing_target == sum_of:
        dollars = 0
        break        
    if new_roll1 == guess1 or new_roll1 == guess2 or new_roll2 == guess1 or new_roll2 == guess2:
        dollars = dollars * 2
        break

未测试。