我希望有一个骰子游戏,用户被问到两个骰子要滚多少次。根据卷内的对,用户将获得总额的奖金。
我遇到的问题是我无法使用当前的for
循环比较数组中的相同位置值。
我得到的错误是:The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
以下是代码:
import numpy as np
import random
def dice_game():
rolls = int(input("how many times would you like to roll the dice: "))
dice_value1 = np.random.randint( 1, 7, rolls)
print(dice_value1)
dice_value2 = np.random.randint( 1, 7, rolls)
print(dice_value2)
return dice_value1, dice_value2
result1, result2 = dice_game()
def dice_game_analysis(x,y):
total = 0
for i in range(len(x)):
if i == y:
if i == 1:
total = 0
if i <= 4:
total += x
if i >= 5:
total += 2*x
print(total)
dice_game_analysis(result1, result2)