0

Python Help

Can you make a program which can differentiate between decimal and perfect number Like. If x== 56.00: Print perfect num Elif x == 56.65 Print. Decimal number

30th Mar 2021, 4:42 AM
pratham jain
pratham jain - avatar
5 odpowiedzi
+ 2
Do you mean a whole number (integer) and a fractional number? You can just check if the number as a float type is greater than its int() type. num = 56.65 if num > int(num): print('dec') else: print('whole') # outputs dec # change num to a number with no fractional part, such as 56.00, to output whole.
30th Mar 2021, 4:48 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Then your question is vague and unclear. It still looks like you just need some form of control flow though. Can you be more thorough and explicit with your questions definition? Your second description sounds like you want a simple if-elif statement, but somehow given your first description and what else you've stated, I don't think this is what you're after.
30th Mar 2021, 5:00 AM
ChaoticDawg
ChaoticDawg - avatar
0
ChaoticDawg No bro I want x= 56.00 It should return Answer found If x== 56.98 it should return. Wrong Answer
30th Mar 2021, 4:52 AM
pratham jain
pratham jain - avatar
0
ChaoticDawg Actually i am preparing a model on RSA algorithm
30th Mar 2021, 4:53 AM
pratham jain
pratham jain - avatar
0
You can either equate the number with its floor value (int(num)) or do this: num % (num // 1).
30th Mar 2021, 4:59 AM
Calvin Thomas
Calvin Thomas - avatar