Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

Learn everything about programming

HackerRank Day 17 More Exceptions 30 days of code solution

YASH PAL, 31 July 2024

In this HackerRank Day 17 More Exceptions 30 days of code problem set, we need to develop a program that can take two input integers and then we need to print the power of that inputs on the output screen and if the numbers are negative integers then we need to print the message that inputs are needed to positive numbers.

Day 17 More Exceptions 30 days of code solution Hackerrank

Problem solution in Python 2 programming.

#Write your code here
class Calculator:
    def power(self, n, p):
        if (n < 0 or p < 0):
            raise Exception("n and p should be non-negative")
        else:
            return n**p
        

Problem solution in Python 3 programming.

#Write your code here
class Calculator:

    def power(self,n, p):
        if n < 0 or p < 0:
            raise Exception("n and p should be non-negative")
        else:
            return pow(n,p)

Problem solution in java programming.

class Calculator{
    public int power(int n, int p) throws Exception{
        if(n < 0 || p < 0){
            throw new Exception("n and p should be non-negative");
        }
        return (int)Math.pow(n,p);
    }
}

Problem solution in c++ programming.

//Write your code here
class Calculator {
    public:
        int power(int n, int p){
            if(n < 0 || p < 0){
                throw invalid_argument("n and p should be non-negative"); 
            }
            
            return pow(n, p);
        }
};

Problem solution in Javascript programming.

//Write your code here
function Calculator() {
    this.power = function(n, p) {
        if (n < 0 || p < 0)
            throw "n and p should be non-negative";
            
        var ans = 1;
        for (i = 0; i < p; i++) {
            ans *= n;
        }
        
        return ans;
    }
}

30 days of code coding problems solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes