python 当日日期_Python程序寻找当日赢家
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 Team1Output : Team1Input : Team1 Team2 Team2 Team1 Team2Output : Team2Code:
碼:
# 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 = 0team2_count = 0# Iterating through all team name # present in a match tuple variablefor team_name in match_tuple :if team_name == "Team1" :team1_count += 1else :team2_count += 1if 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 當日日期
總結
以上是生活随笔為你收集整理的python 当日日期_Python程序寻找当日赢家的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java uuid静态方法_Java U
- 下一篇: c#抽象属性_C#中的抽象属性