Sort by

recency

|

1904 Discussions

|

  • + 0 comments

    class Person: def init(self,initialAge): self.initialAge=initialAge if(self.initialAge<=0): print("Age is not valid, setting age to 0") self.initialAge=0 def amIOld(self): if (self.initialAge<13): print("You are young.") elif (13<=self.initialAge<18): print("You are teenager.") else: print("You are old.") def yearPasses(self): self.initialAge+=1

    t = int(input()) for i in range(0, t): age = int(input())
    p = Person(age)
    p.amIOld() for j in range(0, 3): p.yearPasses()
    p.amIOld() print("") cant get the output due to a missin space how to sovle it and its showin a green box and cant edit the code at all

  • + 0 comments

    im getting wrong anwser, please help me

    class Person: def init(self,initialAge): # Add some more code to run some checks on initialAge self.age = 0 self.Age = initialAge

        print("Age is not valid, Seeting age to 0..")
    def amIOld(self):
        # Do some computations in here and print out the correct statement to the console
        if age < 13:
            print("You are young")
        elif age>=13 and age <18:
            print("You are a teenager")
        else:
            ("You are old")
    def yearPasses(self):
        # Increment the age of the person in here
        self. Age +=1
    

    t = int(input())

  • + 1 comment

    The stub was not available for Java 15 so you can do the challange in Java 8 instead.

  • + 0 comments

    public class Person { private int age;

    public Person(int initialAge) {
        // Add some more code to run some checks on initialAge
        if(initialAge<0){
              System.out.println("Age is not valid, setting age to 0.");
              this.age=0;   
        }
        else
        this.age=initialAge;
    }
    
    public void amIOld() {
        // Write code determining if this person's age is old and print the correct statement:
        if(age<13)
        System.out.println("You are young.");
        else if(age>=13 && age<18)
        System.out.println("You are a teenager.");
        else
        System.out.println("You are old.");
    
    }
    
    public void yearPasses() {
        // Increment this person's age.
        age++;
    }
    
    public static void main(String[] args) {
    
  • + 0 comments

    Person::Person(int initialAge) { // Add some more code to run some checks on initialAge if(initialAge<0) { initialAge=0; cout<<"Age is not valid, setting age to 0.\n"; } else age=initialAge; }

    void Person::amIOld(){
        // Do some computations in here and print out the correct statement to the console 
    

    if(age<13) cout<<"You are young.\n"; else if(age>=13&&age<18) cout<<"You are a teenager.\n"; else cout<<"You are old.\n"; }

    void Person::yearPasses(){
        // Increment the age of the person in here
    

    age=age+1; } }

    return 0;
    

    }