{"id":16692,"date":"2021-08-12T09:25:17","date_gmt":"2021-08-12T03:55:17","guid":{"rendered":"https:\/\/python-programs.com\/?p=16692"},"modified":"2021-11-22T18:38:32","modified_gmt":"2021-11-22T13:08:32","slug":"python-program-to-check-sunny-number","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-sunny-number\/","title":{"rendered":"Python Program to Check Sunny Number"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find the Missing Term of any Arithmetic Progression<\/a> A number is said to be a sunny number if the number next to it is a perfect square. In other words, if N+1 is a perfect square, then N is a sunny number.<\/p>\n Example :<\/p>\n Let Given number(N) = 3<\/p>\n Then N+1= 3+1 = 4 # which is a perfect square.<\/p>\n Therefore ,the Given number “3” is a Sunny Number<\/strong>.<\/p>\n some of the examples are 3,8 ,15, 24, 35 ,48 ,63, 80 ,99, 120 etc.<\/p>\n Given a number, the task is to check whether the given number is a Sunny Number or not.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to check whether the given number is a Sunny Number or not.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" In the previous article, we have discussed Python Program to Find the Missing Term of any Arithmetic Progression Sunny Number: A number is said to be a sunny number if the number next to it is a perfect square. In other words, if N+1 is a perfect square, then N is a sunny number. Example …<\/p>\n
\nSunny Number:<\/strong><\/p>\nGiven number = 3<\/pre>\n
The given number{ 3 } is Sunny Number<\/pre>\n
Given number = 122<\/pre>\n
The given number{ 122 } is not a Sunny Number<\/pre>\n
Program to Check Sunny Number<\/h2>\n
\n
Method #1: Using math.sqrt() function (Static input)<\/h3>\n
\n
# Import the math module using import keyword.\r\nimport math\r\n# Give the number as static input and store it in a variable.\r\nnumb = 3\r\n# Add '1' to the above given number and store it in another variable say\r\n# \"incremented number\".\r\nincremnt_num = numb + 1\r\n# Calculate the Square root of the above obtained number using math.sqrt()\r\n# built-in function\u00a0and store it in another variable.\r\nsqrt_numb = math.sqrt(incremnt_num)\r\n# Multiply the above obtained Square root value with itself and\r\n# store it in another\u00a0variable say \"square_number\".\r\nsquare_number = sqrt_numb * sqrt_numb\r\n# Check if the value of \"square_number \" is equal the \"incremented number\"\r\n# using if conditional statement.\r\nif(square_number == incremnt_num):\r\n # If the statement is True ,Print \"The given number is Strong Number\"\r\n print(\"The given number{\", numb, \"} is Sunny Number\")\r\nelse:\r\n # Else if the statement is False, print \"The given number is Not a Strong Number\" .\r\n print(\"The given number{\", numb, \"} is not a Sunny Number\")\r\n<\/pre>\n
The given number{ 3 } is Sunny Number<\/pre>\n
Method #2: Using math.sqrt() function (User input)<\/h3>\n
\n
# Import the math module using import keyword.\r\nimport math\r\n# Give the number as user input using int(input()) and store it in a variable.\r\nnumb = int(input(\"Enter some random number = \"))\r\n# Add '1' to the above given number and store it in another variable say\r\n# \"incremented number\".\r\nincremnt_num = numb + 1\r\n# Calculate the Square root of the above obtained number using math.sqrt()\r\n# built-in function\u00a0and store it in another variable.\r\nsqrt_numb = math.sqrt(incremnt_num)\r\n# Multiply the above obtained Square root value with itself and\r\n# store it in another\u00a0variable say \"square_number\".\r\nsquare_number = sqrt_numb * sqrt_numb\r\n# Check if the value of \"square_number \" is equal the \"incremented number\"\r\n# using if conditional statement.\r\nif(square_number == incremnt_num):\r\n # If the statement is True ,Print \"The given number is Strong Number\"\r\n print(\"The given number{\", numb, \"} is Sunny Number\")\r\nelse:\r\n # Else if the statement is False, print \"The given number is Not a Strong Number\" .\r\n print(\"The given number{\", numb, \"} is not a Sunny Number\")\r\n<\/pre>\n
Enter some random number = 30\r\nThe given number{ 30 } is not a Sunny Number<\/pre>\n
\n