如何修复比较变量的错误代码



Alice和Bob各自为HackerRank创建了一个问题。评论者对这两个挑战进行评分,根据问题的清晰度、原创性和难度这三个类别,从1到100分打分。

Alice挑战的评分是三元组a = (a[0], a[1], a[2]), Bob挑战的评分是三元组b = (b[0], b[1], b[2])。

任务是通过比较a[0]与b[0], a[1]与b[1], a[2]与b[2]来找到它们的比较点。

If a[i] > b[i], then Alice is awarded 1 point.
If a[i] < b[i], then Bob is awarded 1 point.
If a[i] = b[i], then neither person receives a point.

比较积分是一个人获得的总积分。

给定a和b,确定它们各自的比较点

例子a = [1,2,3]B = [3,2,1]

For elements *0*, Bob is awarded a point because a[0] .
For the equal elements a[1] and b[1], no points are earned.
Finally, for elements 2, a[2] > b[2] so Alice receives a point.

返回数组为[1,1],其中Alice得分第一,Bob得分第二。

功能描述完成下面的编辑功能compareTriplets。

compareTriplets有以下参数:

int a[3]: Alice's challenge rating
int b[3]: Bob's challenge rating

返回
int[2]: Alice's score is in the first position, and Bob's score is in the second.

输入格式第一行包含3个空格分隔的整数,a[0], a[1]和a[2],它们分别是三元组a中的值。第二行包含3个空格分隔的整数,b[0], b[1]和b[2],它们分别是三元组b中的值。

约束
1 ≤ a[i] ≤ 100
1 ≤ b[i] ≤ 100
def rate(alice, bob):
alice_score = sum(a > b for a, b in zip(alice, bob))
return [alice_score, 3 - alice_score]

def parse(participant_count=2):
return (map(int, input().split()) for _ in range(participant_count))

print("Score is", rate(*parse()))

的例子:

1 2 3
3 1 2
Score is [2, 1]