iT邦幫忙

0

Python 學習筆記

  • 分享至 

  • twitterImage
  •  

內容主要是codewar練習的成果 自己寫得以及自己看得懂的覺得寫得好的解答
目的是為了自己哪天懈怠後回來複習使用 不定時更新!

路徑簡化
INPUT:未知的路線提示,有些是矛盾的,比如往南再往北、往東再往西
OUTPUT:簡化後的路線提示
["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]
https://ithelp.ithome.com.tw/upload/images/20210216/20135176voA2xYK3YJ.jpg

數字字母過濾
從list中過濾掉字母及負數

def filterlist(l):
k=[i for i in l if isinstance(i,int)] #過濾掉字母
return [j for j in k if j>=0]

遊戲對打
已知一個建好的class,當中包含名字、血量、每一次攻擊。
題目是定義出一個function來判斷兩個人互打誰最後贏了。攻守互換那句很關鍵也很精采。

def declare_winner(fighter1, fighter2, first_attacker):
cur, opp=(fighter1, fighter2) if first_attacker == fighter1.name else (fighter2, fighter1)
while cur.health>0:
opp.health -= cur.damage_per_attack
cur, opp = opp, cur
return opp.name

Class 牛刀小試
class Ball(object):
def init(self,type='regular'):
self.ball_type=type

def init(self,type='regular'):

self.type=type

# @property

def ball_type(self):

return self.type


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言