![Creative The name of the picture]()
code prints incorrect output in in jupyter notebook whereas it is running correctly on online IDE
# Program for Armstrong Number
# this program prints wrong results in jupyter but running correct in online ide
import math
print("this program is for armstrong numbern")
m=0
p=0
n=int(input("Enter any number: n"))
y=n
while y!=0:
y=y/10
p+=1
y=n
while n!=0:
x=n%10
m+=math.pow(x,p)
n=n/10
if y==m:
print("The given number is an armstrong numbern")
else:
print("The given number is not an armstrong numbern")
{}
1 Answer
1
You should use integer division, rather than "/". Replace y=y/10
and n=n/10
with y=y//10
and n=n//10
.
y=y/10
n=n/10
y=y//10
n=n//10
Using /
for integer division might work - if you happen to be running Python 2. In Python 3, /
is regular (mathematical) division and 11/10 = 1.1 (not 1). Note that the integer division operator //
works both in Python2 and Python3, always use that if you want integer division.
/
/
//
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I know about indentation in python and i use it here
– sy254191
6 hours ago