Python program to find winner of the day

Here, we are going to implement a python program in which we have to find the winner of the day from given two basketball teams. By Ankit Rai Last updated : January 04, 2024

Problem statement

There are two basketball teams (Team1 and Team2) in a school and they play some matches every day depending on their time and interest. Some days they play 3 matches, some days 2, some days 1, etc.

Write a python function, find_winner_of_the_day(), which accepts the name of the winner of each match and returns the name of the overall winner of the day. In case of the equal number of wins, return "Tie".

Example:

Input : Team1 Team2 Team1
Output : Team1

Input : Team1 Team2 Team2 Team1 Team2
Output : Team2

Python code to find winner of the day

# Python3 program to find winner of the day

# function which accepts the name of winner
# of each match of the day and return
# winner of the day

# This function accepts variable number of arguments in a tuple
def find_winner_of_the_day(*match_tuple):
    team1_count = 0
    team2_count = 0

    # Iterating through all team name
    # present in a match tuple variable
    for team_name in match_tuple:
        if team_name == "Team1":
            team1_count += 1
        else:
            team2_count += 1
    if team1_count == team2_count:
        return "Tie"
    elif team1_count > team2_count:
        return "Team1"
    else:
        return "Team2"

# Driver Code
if __name__ == "__main__":
    print(find_winner_of_the_day("Team1", "Team2", "Team1"))
    print(find_winner_of_the_day("Team1", "Team2", "Team1", "Team2"))
    print(find_winner_of_the_day("Team1", "Team2", "Team2", "Team1", "Team2"))

Output

The output of the above example is:

Team1
Tie
Team2

To understand the above program, you should have the basic knowledge of the following Python topics:

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.