Home » Python » Python programs

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.
Submitted by Ankit Rai, on June 25, 2019

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

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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.