我是一名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()
這個問題很可能會重複,當第二功能get_birthday()被調用,詢問他們出生一個月的日子用戶。
這裏是get_today的代碼片段():
def get_today():
x = int(input("Tell me, what day of the month is it today:"))
return x
幫助將大規模感激!
一方面,功能'get_today'需要一個參數,但是當你所有它'main',你不給它任何參數。看起來你實際上並不需要'get_today'的參數,所以在'def get_today(d):' – jss367
中刪除'd'那麼當你調用'get_today'時,你沒有向它傳遞參數一開始... – toonarmycaptain
刪除d提示我一個新的錯誤'TypeError:get_today()缺少1所需的位置參數:'d'' – dezz