我現在正在爲終端設計一個計算器。我有和以前一樣的錯誤。但這次它告訴我:<function div at 0x7faf88c9e488>
代碼爲:https://github.com/mishiki1002/Solo-Calculater/blob/master/Solo-Main.py
解決:
我在蟒蛇的一年半了編程。我玩過def函數和變量。我目前的編程項目是RPG Fantasy類型的遊戲。我目前仍然在乞討,我想知道這是什麼樣的輸出,爲什麼我得到它。我相信它是某種二進制位。
<function showInstructions at 0x7fa8933162f0>
當我編譯我的代碼通過我的終端使用python main.py,這就是我得到的。這是我完整的遊戲源代碼。請留下我的編程意見和建議。也請告訴我,如果我的代碼是sl。。我嘗試記錄所有我可以讓我和我周圍的程序員更容易閱讀它。
真誠喬希
!/usr/bin/python3
#We will import this so that we have a random in counter chance for the game.
#this will all so prove use full when we have attacks sequences and Loot drops
from random import randint
class Character:
def __init__(self):
#This is the name that you have made for your character
self.name = ' '
#Amount of health for you character
self.health = 100
#Max amount of health for your character
self.health_max = 9999
#Damage class to define the attack methods needed to Battle?
def do_damage(self, enemy):
#Defining a varible called damage. Stating that the minimum damage can be 0. And No less than that, for either
damage = min(
# Stating that the minimum damage can be 0. And No less than that, for either character
max(radint(0, self.health)) - randint(0, enemy.health), 0), (enemy.health)
#Actual Damage System
enemy.health = enemy.health - damage
#Printing the product to the user/gamer
if damamge ==0: "%s evades %s's attack." % (enemy.name , self.name)
#If you land a hit
else: print("%s hurts %s!" % (self.name, enemy.name))
#printing your enemys health so you know how much left un-till 0
return enemy.health <= 0
class Enemy(Character):
def __init__(self, player):
#Since we declared that the enemy is a character it takes a characters paramaters
Character.__init__(self)
#It needs a name Like a Goblin
self.name = 'a Goblin'
#And it needs health
self.health = randint(1, 15 + player.health)
class Player(Character):
#Now we are delcaring a Side characters role
def __init__(self, player):
Character.__init__(self)
#when you check out the menu to see how your characters are doing you will see a meesage saying Normal and
#the amount of health they have
self.state = 'Normal'
#Now we set their health
self.health = 100
#Max Health
self.health_max = 9999
#Start Menu will be here
def showInstructions():
print("Sound_Soul")
print("----------")
print("Commmands:")
print(" 'go [direction]'")
print("The Cardinal Directions:")
print(" north")
print(" east")
print(" south")
print(" west")
print (showInstructions)
除了我的回答如下:我過去幾乎對每一行代碼都發表評論,但實際上它使代碼更難閱讀。理想的代碼應該寫得很清楚。我發現留下很多我的評論實際上是讓我的代碼更易於閱讀。對於事情複雜,困惑或其他不明顯的地方,評論是非常好的。但是類似敵人,名字地精的東西很清楚,沒有額外的評論。 – Igor
謝謝伊戈爾的幫助。 –
很高興幫助。請參閱我的答案上的編輯。 – Igor