python 当日日期_Python程序寻找当日赢家
python 當(dāng)日日期
Problem statement:
問(wèn)題陳述:
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.
一所學(xué)校有兩支籃球隊(duì)(Team1和Team2),他們每天根據(jù)時(shí)間和興趣參加一些比賽。 某些時(shí)候他們玩3場(chǎng)比賽,有些日子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".
編寫(xiě)一個(gè)python函數(shù)find_winner_of_the_day() ,該函數(shù)接受每次比賽的獲勝者的姓名,并返回當(dāng)日總獲勝者的姓名。 如果獲勝次數(shù)相等,則返回“ 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 當(dāng)日日期
總結(jié)
以上是生活随笔為你收集整理的python 当日日期_Python程序寻找当日赢家的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java uuid静态方法_Java U
- 下一篇: 使用python学线性代数_二项式过程|