class boy:
"""Details"""
def __init___(self):
print("Details")
def name(self,x,y,z):
a=x.title() + ' '
b=y.title() + ' '
c=z.title()
nam = a + b + c
print(nam)
def age(self,nu):
f = int(num)
if f>18:
return 1
else:
print("\nSorry you must be at least 18 years to continue")
return -1
def p_details(self,cc): #need to print all detals by calling this method.
print("Name :" + self.nam)
print("Age :" + self.f)
print("Country :"+ con)
a = raw_input("Enter the first name :")
b = raw_input("Enter the middle name :")
c = raw_input("Enter the last name :")
num = raw_input("Enter the age :")
inp=boy()
if(inp.age(num) == 1):
con = raw_input("\nPlease enter your country :")
inp.p_details(con)
因爲我是pyhton的新手,這個問題可能看起來愚蠢或愚蠢,但我真的很感謝幫助。我需要的是調用p_details並打印所有的細節。同類中的兩種方法如何在Python中訪問它的成員
你忘了傳遞你的參數。 'boy()'應該有a,b,c作爲參數,然後設置'self.age = a'等等。你正在與成員混合變量。檢查python對象語法。 –
你到目前爲止寫的東西在很多層面都有問題(真的很抱歉)。請閱讀一本關於Python的好書,並在你有特定的東西時回來。按照我的觀點,這太寬泛了。 – SuperSaiyan
@SuperSaiyan我會做..作爲首發將有錯誤,很多錯誤。我需要的是一個幫助,因爲我無法理解爲功能和班級工作,..無論如何,我生病了,謝謝 –