What should be the range in this program?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
26th May 2020, 1:45 PM
Jyoti
5 Answers
+ 4
Hi Jyoti do you know what is an integer? If you know that then it would be easy for you to fill that range. Anyways for any 'n' the range checks from 0 to n-1. So that will not help you find if a number is an integer or not. You can just check whether the entered number is in the given range or not.
26th May 2020, 2:01 PM
Avinesh
Avinesh - avatar
+ 3
The way I would implement it y=input('Enter a number :') j=0 for i in y: if ord(i)>=48 and ord(i)<58: j+=1 continue print("Number is non integer") break if j==len(y): print("Number is integer")
26th May 2020, 2:14 PM
Abhay
Abhay - avatar
+ 2
U r checking number is integer or not. But u r taking only integer input in program. y=int(input('Enter a number :')) So in your program result always be integer. Or error You may check the value is int using these lines. y=eval(input('Enter a number :')) print(isinstance(y,int))
30th May 2020, 12:30 PM
Praveen Verma
Praveen Verma - avatar
+ 1
Thanks
30th May 2020, 1:01 PM
Jyoti
0
Thnks everyone
26th May 2020, 4:01 PM
Jyoti