Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当这一切发生时。我错过什么了吗?_Python_Python 3.3 - Fatal编程技术网

Python 当这一切发生时。我错过什么了吗?

Python 当这一切发生时。我错过什么了吗?,python,python-3.3,Python,Python 3.3,您需要调用该函数 def numbers(num1,num2): num1 = int(input("Enter a number: ")) num2 = int(input("Enter another number: ")) return num1,num2 def display(): print("The numbers that you chose are",num1,"and",num2) def count(): for x in ran

您需要调用该函数

def numbers(num1,num2):
    num1 = int(input("Enter a number: "))
    num2 = int(input("Enter another number: "))
    return num1,num2

def display():
    print("The numbers that you chose are",num1,"and",num2)

def count():
    for x in range(1,11):
        print (x)

我不确定你的最终结果到底是什么,但这不起作用的原因是你从来没有用它做过任何事情

请记住,函数声明(如类声明)只是构建一个工具来完成工作。为了使用该工具,您必须调用该函数(或实例化该类)

现在要真正使用它们,你需要给它们打电话。如果您想将整个过程运行10次(我想是吧?),那么您可以执行以下操作:

def numbers(num1,num2): # You're not actually giving this anything, so why
                        # are there parameters here?
    num1 = int(input("Enter a number: "))
    num2 = int(input("Enter another number: "))
    return num1,num2
# numbers is now a tool in your toolkit. Think of it like a hammer. Just because you
# went and made yourself a hammer doesn't mean your nail is pounded in!

def display():
    print("The numbers that you chose are",num1,"and",num2)
# likewise, display is now a saw. Just because you bought a saw from Home Depot doesn't
# mean your board is cut in two.    

def count():
    for x in range(1,11):
        print (x)
# I'm out of tool analogies, so....

你只需要调用这个函数。函数本身并不称为函数;)

使用

根据你想先打哪一个来订购 或者,您可以通过简单地添加不带引号的“NameOfFunction()”从函数调用函数 转换成其他的功能
希望这有帮助:)

如果您从有史以来最简洁的标题调用这些函数中的任何一个,我会工作得更好。。。
def numbers(num1,num2): # You're not actually giving this anything, so why
                        # are there parameters here?
    num1 = int(input("Enter a number: "))
    num2 = int(input("Enter another number: "))
    return num1,num2
# numbers is now a tool in your toolkit. Think of it like a hammer. Just because you
# went and made yourself a hammer doesn't mean your nail is pounded in!

def display():
    print("The numbers that you chose are",num1,"and",num2)
# likewise, display is now a saw. Just because you bought a saw from Home Depot doesn't
# mean your board is cut in two.    

def count():
    for x in range(1,11):
        print (x)
# I'm out of tool analogies, so....
def numbers(): # I removed those parameters
    num1 = int(input("Enter a number: "))
    num2 = int(input("Enter another number: "))
    return num1, num2

def display():
    num1, num2 = numbers() # CALL numbers
    print("The numbers that you chose are",num1,"and",num2)

def count():
    for _ in range(10):
        display() # CALL display

count() # CALL count
numbers()
display()
count()