当我跑这个没有任何反应。我错过了什么吗?

时间:2014-03-24 19:19:38

标签: 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 range(1,11):
        print (x)

3 个答案:

答案 0 :(得分:0)

您需要调用该函数。

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)

count()

答案 1 :(得分:0)

我不确定你的最终结果是什么,确切地说,但这不起作用的原因是你从不做任何事情。

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

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....

现在实际使用这些,你需要打电话给他们。如果你想整个事情运行10次(我假设?)那么你可以这样做:

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

答案 2 :(得分:0)

你只需要调用该函数。功能不要自己打电话;)

使用

numbers()
display()
count()

根据您想要先打电话的顺序订购它们 或者你可以通过简单地添加" NameofFuction()"来自函数调用函数没有行情 进入其他一些功能 希望这有助于:))