Instagram
youtube
Facebook
Twitter

Python Test Match Series program Codechef solution

Python Test Match Series programme Codechef solution

Problem:

A five-match test series between India and England has just concluded.

Every match could have ended either as a win for India, a win for England, or a draw. You know the result of all the matches. Determine who won the series or if it ended in a draw.

A team is said to have won the series if it wins strictly more test matches than the other team.

Input Format

  • The first line will contain T, the number of test cases. Then the test cases follow.
  • Each test case contains a single line of input, with five space-separated integers R1, R2, R3, R4, and R5 denoting the results of all five matches. Ri=0 denotes that the test match ends in a draw. Ri=1 denotes that the test match is won by India. Ri = 2 denotes that the test match is won by England.

Output Format

For each test output, "DRAW" if the series ends in a draw, "INDIA" if the series is won by India, and "ENGLAND" if the series is won by England.

You may print each character of the string in uppercase or lowercase (for example, the strings "dRaw", "draw", Draw," and "DRAW" will all be treated as identical).

Constraints

  • 1 ≤ T ≤ 1000
  • 0 ≤ Ri ≤ 100

Sample Input:

0 1 2 1 0

0 1 2 1 2

2 2 2 2 1

Sample Output:

INDIA

 DRAW 

ENGLAND

Explanation:

Test Case 1: India wins two matches while England wins one, so India wins the series.

Test Case 2: Both teams win two matches, so the series ends in a draw.

Test Case 3: England won 4 matches while India won 1 match, so England wins the series.

Solution:

def determine_series_winner(results):

    india_wins = results.count(1)

    england_wins = results.count(2)

 

    if india_wins > england_wins:

        return "INDIA"

    elif india_wins < england_wins:

        return "ENGLAND"

    else:

        return "DRAW"



 

T = int(input(“Enter the number of terms: “))

 

for _ in range(T):

    results = list(map(int, input(Enter the results of each match of a 5 match series: “).split()))

    series_winner = determine_series_winner(results)

 

    print(series_winner)

Steps to solve this problem:

  1. Ask the user to enter the number of terms.
  2. In the loop, ask the user to enter the results of each match of a 5-match series, and using the map() function, get iterator objects, and using the list() function, pack them in a list and store the list in results.
  3. Call the function determine_series_winner. and provide the actual argument, which is the result of the called function, and store the result in series_winner.
  4. Print the value of series_winner.
  5. Define a function named determine_series_winner and pass the results as an argument.
  6. Using the count() function on results, count the number 1 and the number 2 and store them in india_wins and england_wins, respectively.
  7. Check if india_wins is greater than England_wins, then return "India."
  8. Check if England_wins is greater than India_wins, then return ENGLAND."
  9. If both conditions above evaluate to false, then return "DRAW."