python def函数的二进制输出

时间:2016-03-03 22:35:05

标签: function python-3.x binary

新:

我正在研究终端的计算器。我遇到了和以前一样的错误。但这次它告诉我:<function div at 0x7faf88c9e488>

代码位于:https://github.com/mishiki1002/Solo-Calculater/blob/master/Solo-Main.py

解决:

我已经在python中编程了一年半。我玩过def函数和变量。我目前的编程项目是RPG Fantasy型游戏。我目前仍在乞讨,我想知道这是什么样的输出,为什么我得到它。我相信它是某种二进制位。

<function showInstructions at 0x7fa8933162f0>

当我通过我的终端使用python main.py编译我的代码时,这就是我得到的。这是我完整的游戏源代码。请留下任何评论和/或建议我的编程。如果我的代码很草率,请告诉我。我试着把所有的文件记录下来,这对我和我周围的程序员来说更容易阅读。

真诚的约什

   !/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)

1 个答案:

答案 0 :(得分:0)

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

编辑:

还有一件事:调用函数时不需要使用print,因为函数中已有print语句。这会导致“无”打印在预期文本下方,因为默认情况下该函数确实返回None