answersLogoWhite

0


Best Answer

Unless someone is willing to write an entire program for you (which I would, but I don't have the patience to learn an entire new programming language to answer one question) I think the best you'll get is this:

  • To get user input: var = raw_input("Enter something: ")
  • To separate a number into its single digits: var = "your number"

    var2 = list(var) var2 will have what seems to be an array of each number.

  • foreach loops in Python are just: for "item" invar2: # do something with item such as cube it and add it to another variable set aside for the overall value. Or cube it and subtract it from the original and at the end check if what used to be the original is now zero.
  • Lastly, if it's in quotes you can change it.

Another way to do it (which would be easier but would probably take slightly longer and has a limit of number 10 digits or less) would be to check to see if the number is in the list in the related link.

I've been curious about Python before so if I end up getting to the point that I can write a simple program in it I'll add it to the related links.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

def isArmstrongNumber(num):

factor = len(str(num))

res = 0

for digit in str(num):

res = res + (int(digit)**factor)

if (num == res):

return True

else:

return False

for i in range(1000):

if isArmstrongNumber(i):

print i,

#Result:

0 1 2 3 4 5 6 7 8 9 153 370 371 407

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a python program to check a number is Armstrong number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a java program to check a number is Armstrong number?

import java.io.*; public class Jerry { public static void main(String as[]) throws IOException { int k=Integer.parseInt(as[0]); int n=k; int d=0,s=0; while(n>0) { d=n%10; s=s+(d*d*d); n=n/10; } if(k==s) System.out.println("Armstrong number"); else System.out.println("not Armstrong number"); } }


How do you make a program in python using do while loop to display the multiplication table of number from one to ten?

a = 0while a < 10 :a += 1print (a)Write the above simple script in a text editor (I use nano). Save as loop.py in home folder. To run, open a terminal and at the prompt, write: python loop.pyResult:rodney@downstairs:~$ python loop.py12345678910


How do you write a horoscope program on python?

Hi gys, are you looking to write a program to know the sign depends on the birth date or horoscope on python? write down following codes on python, those will make a nice program. #This program will get the horoscope sign. def getSign(): name = raw_input ("Enter Your Name: ") month = raw_input("Enter Birth Month: ") day = int(raw_input("Enter Birth Day of Month: ")) if month "y": main() letter = raw_input("Go again? (y/n): ")


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program

Related questions

Write a java program to check a number is Armstrong number?

import java.io.*; public class Jerry { public static void main(String as[]) throws IOException { int k=Integer.parseInt(as[0]); int n=k; int d=0,s=0; while(n&gt;0) { d=n%10; s=s+(d*d*d); n=n/10; } if(k==s) System.out.println("Armstrong number"); else System.out.println("not Armstrong number"); } }


How do you make a program in python using do while loop to display the multiplication table of number from one to ten?

a = 0while a < 10 :a += 1print (a)Write the above simple script in a text editor (I use nano). Save as loop.py in home folder. To run, open a terminal and at the prompt, write: python loop.pyResult:rodney@downstairs:~$ python loop.py12345678910


How do you write a horoscope program on python?

Hi gys, are you looking to write a program to know the sign depends on the birth date or horoscope on python? write down following codes on python, those will make a nice program. #This program will get the horoscope sign. def getSign(): name = raw_input ("Enter Your Name: ") month = raw_input("Enter Birth Month: ") day = int(raw_input("Enter Birth Day of Month: ")) if month "y": main() letter = raw_input("Go again? (y/n): ")


How do you write a program to input radius of a circle and calculate the area or circumferences of the cirlce?

In which computer language?


Write a program to convert a 2 digit BCD number into hexadecimal number?

Write a program to convert a 2-digit BCD number into hexadecimal


What program should you move on to after Game Maker if you already know a language such as python?

If you have an interest in games, and know how to program in python you should investigate pygame. Pygame is a python module which is designed to let you use python to write games with sprites and sound. For an introduction to Pygame, see chapter 17 in Al Sweigart's free ebook Invent Your Own Computer Games With Python. (see related link) The Pygame module is available for download from pygame.org.


How do you write a Java program to see whether a number is Armstrong or not... using Buffered Reader and stuff ....?

import java.io.*; class Armstrong { public static void main()throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a number"); int a=Integer.parseInt(in.readLine()); int n1=a,rev=0,d=0; while(a!=0) { d=a%10; rev=rev+d*d*d; a=a/10; } if(rev==n1) System.out.println("It is a armstrong number "); else System.out.println("It is not a armstrong number "); } }


How to write a program in python to print the reverse of a number?

In python, type the following into a document. NOTE: Sentences following a # symbol are comments, and are not necessary for the program to run. #!/usr/bin/python #This program takes a input from a user and reverses it. number = input("Type a number: ") #This takes input from a user. a = len(number) #This finds the length of the number reverse = "" #This sets the variable reverse to an empty string. for i in number: a = a-1 #The places in a string start from 0. The last value will be the length minus 1.reverse = reverse + number[a] #Makes the number's last digit the new string's first. print("The reverse of", number, "is", reverse + ".") #prints the resulting string. This program will take any sequence of characters and reverse them. The final value is a string, but if an integer is needed, one needs only to add the line reverse = int(reverse) above the print statement. However, this will stop the program from being able to reverse strings, as it is not possible to convert a string to an integer if it is not a number.


2 Write a program to convert a 2-digit BCD number into hexadecimal?

WRITE A PROGRAM TO CONVERT A 2-DIGIT bcd NUMBER INTO HEXADECIMAL


What is meant by functions on python?

Python programming allows you to write your own programs. For example, to write a function named double that returns the number that you input, but doubled, we would write the following (where &gt;&gt;&gt;&gt; indicates a tab space) def double(x): &gt;&gt;&gt;&gt;x=x*2 &gt;&gt;&gt;&gt;return x


Write a program which takes any number of days from the user the program should display the number of years number of months formed by these days as well as the remaining days?

Write a program which takes any number of days from the user. the program should display the number of years, number of months formed by these days as well as the remaining days.


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement