will look for the next perfect square. Check the argument to see if it is a perfect square itself, if it is not then return -1 otherwise look for the next perfect square. for instance if you pass 121 then the script should return the next perfect square which is 144. """ def find_next_square(sq):     root = sq ** 0.5     if root.is_integer():

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question

"""
This program will look for the next perfect square.
Check the argument to see if it is a perfect square itself, if it is not then return -1 otherwise
look for the next perfect square.
for instance if you pass 121 then the script should return the next perfect square which is 144.
"""

def find_next_square(sq):
    root = sq ** 0.5
    if root.is_integer():
        return (root + 1)**2
    return -1

def find_next_squa2(sq):
    """ Alternatie method, works by evaluating anything non-zero as True (0.0001 --> True) """
    root = s**0.5.

 

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning