Study Gang discussion
Subjects
>
Computer Science
date
newest »
newest »
message 1:
by
phideɭia
(new)
Apr 17, 2024 09:14AM
Mod
reply
|
flag
Apple˚✧ wrote: "the subject which makes the avg grades go higher 😌"
yeahhh
yeahhh
Can someone please please pleeease help me understand what armstrong number is and how this code is meant to help verify if a number is armstrong number or not, I CANT UNDERSTAND IT
n=int(input("enter:"))
sum=0
x=n
while n!=0:
a=n%10
sum=sum+a**3
n=n//10
if sum==x:
print("yes")
else:
print("no")
n=int(input("enter:"))
sum=0
x=n
while n!=0:
a=n%10
sum=sum+a**3
n=n//10
if sum==x:
print("yes")
else:
print("no")
Dorcas wrote: "Can someone please please pleeease help me understand what armstrong number is and how this code is meant to help verify if a number is armstrong number or not, I CANT UNDERSTAND IT
n=int(input("en..."
armstrong number is a number that equals the sum of its digit's cubes
n=int(input("en..."
armstrong number is a number that equals the sum of its digit's cubes
Dorcas wrote: "Can someone please please pleeease help me understand what armstrong number is and how this code is meant to help verify if a number is armstrong number or not, I CANT UNDERSTAND IT
n=int(input("en..."
% stands for modulo - it gives the remainder
// stands for floor division - it gives the greatest integer function of the quotient
so, basically you're obtaining a number for input as n, and taking initial sum as 0
you're assigning x the value of 'n' to keep it aside for equating it with the sum of its cubes while operating on 'n'
then, in the while loop (while ensuring n doesn't become 0):
1) you're obtaining the last digit of n and assigning it to 'a'
2) then, updating the value of 'sum' which you would have to check if it's equal with the original number later
3) now, you're updating n, by removing its last digit
then, it goes back in the loop
finally, you're checking if 'x' equals with the 'sum', if yes, then the output is yes, else, it's no.
I have a simple, alternative code though:
n= int(input('Enter no.: '))
s=str(n)
sum=0
for a in s:
sum+=int(a)**3
if sum==n:
print(n, ' is armstrong')
(with appropriate indentation ofc)
n=int(input("en..."
% stands for modulo - it gives the remainder
// stands for floor division - it gives the greatest integer function of the quotient
so, basically you're obtaining a number for input as n, and taking initial sum as 0
you're assigning x the value of 'n' to keep it aside for equating it with the sum of its cubes while operating on 'n'
then, in the while loop (while ensuring n doesn't become 0):
1) you're obtaining the last digit of n and assigning it to 'a'
2) then, updating the value of 'sum' which you would have to check if it's equal with the original number later
3) now, you're updating n, by removing its last digit
then, it goes back in the loop
finally, you're checking if 'x' equals with the 'sum', if yes, then the output is yes, else, it's no.
I have a simple, alternative code though:
n= int(input('Enter no.: '))
s=str(n)
sum=0
for a in s:
sum+=int(a)**3
if sum==n:
print(n, ' is armstrong')
(with appropriate indentation ofc)
Dorcas wrote: "Can someone please please pleeease help me understand what armstrong number is and how this code is meant to help verify if a number is armstrong number or not, I CANT UNDERSTAND IT
n=int(input("en..."
did you get it now? :)
n=int(input("en..."
did you get it now? :)
YEAAHHHHH!!!! I GOT IT OMG THANKS A LOT PHIDELIAA :D <3





