code prints incorrect output in in jupyter notebook whereas it is running correctly on online IDE

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")





I know about indentation in python and i use it here
– sy254191
6 hours ago







Please paste your code as it is, select it and click on {} to format it as code.
– Thierry Lathuille
6 hours ago


{}





could you improve the question by including the error that the code is generating and any steps you have taken to debug it so far? The chances of useful responses increases with a more descriptive question.
– olly_uk
6 hours ago





Works for me. Include what input you used and what error you get.
– Mathieu
5 hours ago





my input is 371 and output i get is the statement written in else block of my code on my jupyter notebook
– sy254191
5 hours ago






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.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP