Need help with a challenging school assignment

The problem presented in this lab is an active research area in Computer Science called differential privacy and secure (multi-party) computation. In this lab, we won’t be able to use a differentially private algorithm, so we will assume that the users stored their data secretly somewhere and cannot see each other’s values.

Three friends finished the test and want to secretly compare their test scores. They do not want to know each other’s exact score, but they do want to know who achieved the best results for this test.

Instructions

1. Input the names and scores of the three friends one after another. (Check out the example input below)
2. Your program should store both names and scores. Store the names in the order that they were input in one tuple and the scores in another tuple.
3. Call the `compare_scores()` function and print the returned name(s) of the student(s) with the highest score(s).

Write the `compare_scores(names, scores)` function that expects two parameters:

• a tuple with the names
• a tuple with the scores corresponding to the respective name

The function compares the scores and returns one or more names (from the input tuple) as a string.

1. If there is one best score - return the name of the friend that achieved that score.
2. If there are two friends with equal highest scores - return a string with both names, separated by space, in the order of input.
3. If all three friends achieved equal scores - return a string with all three names, separated by space, in the order of input.

Examples

Input

``````Ann
10
Maria
9
Cindy
7
``````

Output

``````Ann
``````

Input

``````Ann
10
Maria
9
Cindy
10
``````

Output

``````Ann Cindy
``````

Input

``````Ann
10
Maria
10
Cindy
10
``````

Output

``````Ann Maria Cindy
``````

Notes

• Use the <, >, >=, <= and == operators
• Use `elif` and/or nested `if`s
• Be careful with the indentation (i.e., the spaces before the blocks of code), especially in nested `if`s.

my code:

``````def compare_scores(names, scores):
combined_name_and_score = {}
for index, value in enumerate(names):
combined_name_and_score[value] = scores[index]
combined_name_and_score = dict(sorted(combined_name_and_score.items(), key=lambda item: item[1], reverse=True))
sorted_name = combined_name_and_score.keys()
sorted_numbers = combined_name_and_score.items()
high_score = max(scores)
lowest_score = min(scores)

high_score_position = scores.index(high_score)
middle_score_position = scores.index((len(scores)/2)-1)
low_score_position = scores.index(lowest_score)
for score in scores:
if score != max(scores):
print(sorted_name[high_score_position],sorted_name[middle_score_position],sorted_name[low_score_position])
break
else:
for name in names:
print(name, end=' ')

if __name__ == "__main__":
name1 = input()
num1 = int(input())
name2 = input()
num2 = int(input())
name3 = input()
num3 = int(input())
names = (name1,name2,name3)
nums = (num1,num2,num3)
compare_scores(names, nums)
``````

What problem are you having with it?

these are the errors I got:
1:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 10 Betty 9 Cindy 8

Expected output

Ann

2:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 10 Betty 10 Cindy 8

Expected output

Ann Betty

3:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 10 Betty 9 Cindy 10

Expected output

Ann Cindy

4:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 8 Betty 10 Cindy 10

Expected output

Betty Cindy

5:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 10 Betty 10 Cindy 10

Expected output

Ann Betty Cindy

6:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 9 Betty 10 Cindy 8

Expected output

Betty

7:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 9 Betty 9 Cindy 10

Expected output

Cindy

8:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 1 Betty 2 Cindy 3

Expected output

Cindy

9:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 3 Betty 2 Cindy 1

Expected output

Ann

10:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

Input

Ann 1 Betty 3 Cindy 2

Expected output

Betty

11:Compare outputkeyboard_arrow_up

0 / 1

Traceback (most recent call last): File “main.py”, line 33, in compare_scores(names, nums) File “main.py”, line 12, in compare_scores middle_score_position = scores.index((len(scores)/2)-1) ValueError: tuple.index(x): x not in tuple

12:Unit testkeyboard_arrow_up

0 / 2

compare_scores() with the example from the instructions

Test feedback

You might have errors in your code, or an incorrect function name (check its spelling). Python error message is: tuple.index(x): x not in tuple

13:Unit testkeyboard_arrow_up

0 / 2

compare_scores() with the random values

Test feedback

You might have errors in your code, or an incorrect function name (check its spelling). Python error message is: tuple.index(x): x not in tuple

The line is:

``````middle_score_position = scores.index((len(scores)/2)-1)
``````

and it’s saying that the value you’re looking for isn’t there, so try adding a print statement to show what’s in `scores` and what the value of `(len(scores)/2)-1` is.

And compare it with the preceding and following lines. That line definitely looks suspect to me!

Your function returns None as it doesn’t contain return/yield. So automated system gives “Your program produced no output”