Q:

Python program to find winner of the day

belongs to collection: Python basic programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Code:

# 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

Team1
Tie
Team2

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program for Tower of Hanoi... >>
<< Python program for swapping the value of two integ...