Python 尝试调用函数时出错

Python 尝试调用函数时出错,python,function,Python,Function,我是Python的初学者,我正在尝试编写一个程序,它本质上是一个使用函数的“算命先生”。在调用函数get_today()时,我似乎遇到了一个问题,该函数的编写目的是从用户处获取当月某一天的输入,并将其作为整数返回 但是,当我调用该函数时,会出现一个错误提示: TypeError: get_today() missing 1 required positional argument: 'd' 我试过玩一些游戏,但不明白这意味着什么。以下是主要功能: def main(): print(

我是Python的初学者,我正在尝试编写一个程序,它本质上是一个使用函数的“算命先生”。在调用函数get_today()时,我似乎遇到了一个问题,该函数的编写目的是从用户处获取当月某一天的输入,并将其作为整数返回

但是,当我调用该函数时,会出现一个错误提示:

TypeError: get_today() missing 1 required positional argument: 'd'
我试过玩一些游戏,但不明白这意味着什么。以下是主要功能:

def main():

    print("Welcome​ ​to​ ​Madame​ ​Maxine's​ ​Fortune​ ​Palace. Here,​ ​we​ ​gaze​ ​deeply into​ ​your​ ​soul​ ​and​ ​find​ ​the secrets​ ​that​ ​only​ ​destiny​ ​has​ ​heretofore​ ​known!")
    print("")
    print("The​ ​power​ ​of​ ​my​ ​inner​ ​eye​ ​clouds​ ​my​ ​ability​ ​to​ ​keep track​ ​of mundane​ ​things​ ​like​ ​the​ ​date.")
    d = get_today()
    print("Numerology​ ​is​ ​vitally​ ​important​ ​to​ ​fortune​ ​telling.")
    b = get_birthday()

    if(d >=1 and d <= 9):
        print("One more question before we begin.")
        a = likes_spicy_food()
        print("I will now read your lifeline")
        read_lifeline(d,b,a)
    if(d >= 10 and d <= 19):
        print("I will now read your heartline.")
        read_heartline(d,b)
    if(d >= 20 and d <= 29):
        print("I need one last piece of information.")
        m = get_birthmonth()
        read_headline(b,m)

    if(d == 30 or d == 31):
        print("Today is a bad day for fortune telling.")

        print("These insights into your future are not to be enjoyed or dreaded, they simply come to pass.")
        print("Good day.")

main()

非常感谢您的帮助

当我按原样运行此代码时,它不会告诉我您的错误。但是,当我使用
d=get_today()
作为
d=get_today(d)
main
下运行此代码时,我得到了您得到的错误

调用函数时,括号之间的内容就是传递给函数的内容。由于您尚未分配
d
,因此无法将其传入。此外,函数不需要传入变量,因为它只是用户输入

试试这个:

def main():
    #code
    d = get_today()
    #more code

def get_today()
    #the function with return statement

main()

首先,函数
get_today
接受一个参数,但是当您将它全部放在
main
中时,您不会给它任何参数。看起来您实际上不需要
get_today
的参数,因此请删除
def get_today(d)中的
d
当您调用
get_today
时,您不会首先将参数传递给它……删除d会提示我一个新错误
类型错误:get_today()缺少1个必需的位置参数:“d”
删除d提示我出现新错误
TypeError:get_today()缺少1个必需的位置参数:“d”
是否从
def get_today()
中删除了
d
?是的,我将发布原始问题中的编辑内容@Brandon Molyneaux我猜你也把它从
main
删除了?是的,我确实删除了。
def main():
    #code
    d = get_today()
    #more code

def get_today()
    #the function with return statement

main()