Sort by

recency

|

1894 Discussions

|

  • + 0 comments

    Python3 solution: On the same point as per my earlier message, I referred to the solution present in the Editorial section as well and tried it. It is still failing with the initial test case where initalAge is -1. Can anyone please advise on what is wrong in the code?

    class Person: def init(self,initialAge): if (initialAge < 0): print("Age is not valid, setting age to 0") self.age = 0 else: self.age = initialAge

    def amIOld(self):
        if self.age >= 18:
            print("You are old.")
        elif self.age >= 13:
            print("You are a teenager.")
        else:
            print("You are young.")
    
    def yearPasses(self):
        self.age += 1
    
  • + 0 comments

    Python3 solution: Is there something wrong with my code? The test cases are failing. I checked the solutions from the leaderboard (even though I will not get the points now :-)) and its similar to that. I am confused here. class Person: def init(self,initialAge): if initialAge < 0: self.age = 0 print("Age is not valid, setting age to 0") else: self.age = initialAge def amIOld(self): if self.age < 13: print("You are young.") elif 13 <= self.age < 18: print("You are a teenager.") else: print("You are old.") def yearPasses(self): self.age += 1

  • + 0 comments

    I think my solution it's ok, a blank line is being printed at the end of execution but I'm not allowed to modify that code and because of that I think the outcome is a "wrong" answer, please let me know if you see something wrong with my solution

    process.stdin.resume();
    process.stdin.setEncoding('ascii');
    
    var input_stdin = "";
    var input_stdin_array = "";
    var input_currentline = 0;
    
    process.stdin.on('data', function (data) {
        input_stdin += data;
    });
    
    process.stdin.on('end', function () {
        input_stdin_array = input_stdin.split("\n");
        main();    
    });
    
    function readLine() {
        return input_stdin_array[input_currentline++];
    }
    function Person(initialAge) {
      this.age = initialAge;
      if (this.age < 0) {
          this.age = 0;
          console.log("Age is not valid, setting age to 0.");
      }
        // Add some more code to run some checks on initialAge
        this.amIOld=function(){
                // Do some computations in here and print out the correct statement to the console
                if (this.age < 13) {
                    console.log("You are young.");
                } else {
                    if ( this.age < 18) {
                        console.log("You are teenager.");
                    } else {
                        console.log("You are old.");
                    }
                }
        };
       this.yearPasses=function(){
              // Increment the age of the person in here
              this.age++;
       };
    }
    
    
    function main() {
    
    var T=parseInt(readLine());
    for(i=0;i<T;i++){
        var age=parseInt(readLine());
        var p=new Person(age);
        p.amIOld();
        for(j=0;j<3;j++){
            p.yearPasses();
            
        }
        p.amIOld();
        console.log("");   
        }
    }
    
  • + 0 comments

    the code doesn't print the you are old statement what could be the reason` import java.io.; import java.util.;

    public class Person { private int age;

    public Person(int initialAge) {
        // Add some more code to run some checks on initialAge
    
         if(initialAge>0){
              age=initialAge;
    
    
          }
          else{
    
            System.out.println("Age is not valid, setting age to 0.");
              this.age=0;
          }
    
    }
    
    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<28)
          {
              System.out.println("You are a teenager..");
          }
          else if(age >=18)
          {
              System.out.println("You are old..");
        }
    
    }
    
    public void yearPasses() {
        // Increment this person's age.
          this.age=age++;
    }
    
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int i = 0; i < T; i++) {
            int age = sc.nextInt();
            Person p = new Person(age);
            p.amIOld();
            for (int j = 0; j < 3; j++) {
                p.yearPasses();
            }
            p.amIOld();
            System.out.println();
        }
        sc.close();
    }
    

    } `

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Person {
        private int age;	
      
    	public Person(int initialAge) {
      		// Add some more code to run some checks on initialAge
              
              if(initialAge>0){
                  age=initialAge;
                //   System.out.print("Age is not valid, setting age to 0.");
                //   this.age=0;
                  
              }
              else{
                //   this.age=initialAge;
                System.out.println("Age is not valid, setting age to 0.");
                  this.age=0;
              }
    	}
    
    	public void amIOld() {
      		// Write code determining if this person's age is old and print the correct statement:
            // System.out.print(/*Insert correct print statement here*/);
            if(age<13 ){
                System.out.print("You are young.\n");
            }
            if(age>=13 && age<18){
                System.out.print("You are a teenager.\n");
            }
            if(age>=18){
                System.out.print("You are old.\n");
            }
    	}
    
    	public void yearPasses() {
      		// Increment this person's age.
              age++;
    	}
    
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int T = sc.nextInt();
    		for (int i = 0; i < T; i++) {
    			int age = sc.nextInt();
    			Person p = new Person(age);
    			p.amIOld();
    			for (int j = 0; j < 3; j++) {
    				p.yearPasses();
    			}
    			p.amIOld();
    			System.out.println();
            }
    		sc.close();
        }
    }