[閒聊] 女巫獵人random一直跑Trun?
import random
class Witch:
def __init__(self,name,level):
self.name=name
self.level=level
def __repr__(self):
return ('{}(lv{})'.format(self.name,self.level))
def witchcraft_attack(self):
return random.randint(1,10)*self.level
class FireWitch(Witch):
def __init__(self,name,level,firestaff):
super().__init__(name,level)
self.firestaff=firestaff
def witchcraft_attack(self):
base_attack=super().witchcraft_attack()
if self.firestaff== True:
print("女巫噴火啦")
return base_attack*2
else:
return base_attack
firewitch=FireWitch('火焰女巫',5,random.choice([False,True]))
目前想說 random ture * 2 false * 1
但執行
firewitch.witchcraft_attack()
女巫噴火啦
Out[139]: 100
firewitch.witchcraft_attack()
女巫噴火啦
Out[140]: 80
firewitch.witchcraft_attack()
女巫噴火啦
Out[141]: 50
女巫一直噴火 感覺random 一直跑ture
為啥不會跑false呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 117.56.227.246 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1569474575.A.19B.html
※ 編輯: gogogo123 (117.56.227.246 臺灣), 09/26/2019 13:10:23
※ 編輯: gogogo123 (117.56.227.246 臺灣), 09/26/2019 13:29:32
→
09/26 13:46,
5年前
, 1F
09/26 13:46, 1F
→
09/26 14:43,
5年前
, 2F
09/26 14:43, 2F
→
09/26 14:44,
5年前
, 3F
09/26 14:44, 3F
推
09/27 20:55,
5年前
, 4F
09/27 20:55, 4F
推
09/28 09:27,
5年前
, 5F
09/28 09:27, 5F
→
09/28 09:27,
5年前
, 6F
09/28 09:27, 6F
→
09/28 09:27,
5年前
, 7F
09/28 09:27, 7F
Python 近期熱門文章
PTT數位生活區 即時熱門文章