Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9102639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:25:53+00:00 2026-06-17T01:25:53+00:00

I made a simple script which finds the Square root of a number. The

  • 0

I made a simple script which finds the Square root of a number. The user inputs a number and it finds the square root and shows the result. I want it to check whether the input was a number or not. If it was a number it’ll continue else it’ll show a message, and reset.

I tried using:

while num != int(x):
    print "That is not a valid number"
    return self.page()

But that only shows an error.
Can someone help me out on this?

Here is the code:

import math
import sys

class SqRoot(object):
    def __init__(self):
        super(SqRoot, self).__init__()

        self.page()

    def page(self):
        z = 'Enter a number to find its square root: '
        num = int(raw_input(z))
        sqroot = math.sqrt(num)
        print 'The square root of \'%s\' is \'%s\'' % (num, sqroot)
        choose = raw_input('To use again press Y, to quit Press N: ')
        if choose == 'Y' or choose == 'y':
            return self.page()
        elif choose == 'N' or choose == 'n':
            sys.exit(0)

print "SqRoot Finder v1.0"
print "Copyright(c) 2013 - Ahnaf Tahmid"
print "For non-commercial uses only."
print "--------------------------------"

def main():
    app = SqRoot()
    app()

if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:25:55+00:00Added an answer on June 17, 2026 at 1:25 am

    One of the python principles is EAFP:

    Easier to ask for forgiveness than permission. This common Python coding style assumes the existence of valid keys or attributes and catches exceptions if the assumption proves false.

    x = raw_input('Number?')
    try:
        x = float(x)
    except ValueError:
        print "This doesn't look like a number!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've made a simple script which will reveal a div (inside another) when hovered
I've made a simple symfony2 console script which is supposed to convert data from
I made a simple jquery script to sort content of the page on clicking
hi i've got question i've made simple form with attachment input and i want
I've created a simple script that allows a user to post a message, question
I use this custom, simple script I made, somehow it's failing but it always
I have a simple doubt. I have made a custom ActionScript mxml component, which
I have a site which I have converted to use cms made simple. It
Updated below: I have a script which has a function I made that calculates
I made a simple form with radio buttons and submit button. On submit, check()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.