2016-03-03 57 views
2

新功能:python def函数的二进制输出

我现在正在为终端设计一个计算器。我有和以前一样的错误。但这次它告诉我:<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) 
+0

除了我的回答如下:我过去几乎对每一行代码都发表评论,但实际上它使代码更难阅读。理想的代码应该写得很清楚。我发现留下很多我的评论实际上是让我的代码更易于阅读。对于事情复杂,困惑或其他不明显的地方,评论是非常好的。但是类似敌人,名字地精的东西很清楚,没有额外的评论。 – Igor

+0

谢谢伊戈尔的帮助。 –

+0

很高兴帮助。请参阅我的答案上的编辑。 – Igor

回答

0

你得到的是因为你只使用函数名showInstructions,而不是像这样showInstructions()到函数的调用。

编辑:

一两件事:你不需要调用你的函数时,你已经在你的函数中打印语句也可以使用打印。这会导致“无”打印在预期的文本下方,因为该功能默认情况下的确会返回None