python 当日日期
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.
一所学校有两支篮球队(Team1和Team2),他们每天根据时间和兴趣参加一些比赛。 某些时候他们玩3场比赛,有些日子2,有些日子1等。
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".
编写一个python函数find_winner_of_the_day() ,该函数接受每次比赛的获胜者的姓名,并返回当日总获胜者的姓名。 如果获胜次数相等,则返回“ 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
翻译自: https://www.includehelp.com/python/find-winner-of-the-day.aspx
python 当日日期