0
def sqrt():

    x = input('enter a number:' )
    x= int()           
    if x == int:
        a = x*x      
        print (a)
    else:
           print ('this is not a number')

this is my code, i wanted to input a number and multiply it by itself, but it didn't work out. when i run my program as;

sqrt()

enter a number:10 this is not a number

but the code that i have written should give 'True' to the 'if' statement. any helps?

wannabedon
  • 37
  • 2
  • 5
  • 4
    You have several basic errors, I'd strongly recommend reading a structured tutorial. In the meantime the canonical duplicate is https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response – jonrsharpe Jul 28 '18 at 14:44

1 Answers1

4

You are calling int without argument, so you get x=0; the other problem is, that a value of type int is never equal to the type int.

Use exceptions:

def sqrt():
    try:
        x = int(input('enter a number:' ))
    except ValueError:
        print('this is not a number')
    else:
        a = x*x      
        print(a)
Daniel
  • 42,087
  • 4
  • 55
  • 81