kiran_raj_r kiran_raj_r - 3 months ago 6x
Python Question

how can two methods in same class can access it members in python

class boy:

def __init___(self):

def name(self,x,y,z):
a=x.title() + ' '
b=y.title() + ' '
nam = a + b + c

def age(self,nu):
f = int(num)
if f>18:
return 1
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 :")

if(inp.age(num) == 1 ):
con = raw_input("\nPlease enter your country :")

As i am new into pyhton the question may seem silly or foolish but i really appreciate a help. What i need is to call p_details and print all the details.

class boy():
    def __init___(self, num):
        self.age = int(num)

num = raw_input("Enter the age :")

inp = boy(num)

if inp.age < 18:

Your class should work like this. The way you wrote it, inp has no age attribute to evaluate. But as pointed out in the comments, there's really a lot wrong with your code there. The way you're using methods suggests you aren't clear on how classes and methods work, exactly. Also, getting user input opens up a whole host of issues - like what happens if the user doesn't enter a numeral when asked, and instead types, say, "old enough"?