Commit 43964946 by BellCodeEditor

auto save

parent 2ef0ab34
Showing with 21 additions and 15 deletions
class Hero: import random
def __init__(self,name,hp,attack): alist = []
self.level=1 for i in range(1,101):
self.name= name alist.append(i)
self.hp= hp num = random.choice(alist)
self.attack = attack def binary_search(alist,num):
def qwe(self): low = 0
self.level=self.level+1 high = len(alist) - 1
self.hp=self.hp+5000 while low <= high:
self.attack=self.attack+1000 mid = (low+high)//2
yase = Hero('亚瑟',1000,300) guess = alist[mid]
print(yase.hp) if guess == num:
yase.qwe() return mid
print(yase.hp) elif guess < num:
\ No newline at end of file low = mid + 1
elif guess > num:
high = mid - 1
return None
result = binary_search(alist,num)
print(result)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment