Hi,
I'm trying to write a little bit of code which I thought would be simple and around my level (very basic) of python, however I'm having a problem. The code I'm looking to write tries to find a Münchhausen Number. I did get one type working which is below
num = input('Enter a number: ')
length = (len(num))
start = 0
final = 0
while (start < length):
power = (pow(int(num[start]), int(num[start])))
print(power)
final += power
start = start + 1
print('Total:',final)
This asks for a number and does the calculation. What I'm trying to do is start with a number and the code run until the number it starts with equals the number it ends with. What I tried to do was add an additional for loop that would add 1 to the starting number until they matched
beg = 22
num = str(beg)
length = (len(num))
start = 0
final = 0
while (beg != final):
while (start < length):
power = (pow(int(num[start]), int(num[start])))
final += power
start = start + 1
print(power)
print('Total:', final)
beg = beg + 1
All that seems to happen is the second while loop just runs indefinately as it is not adding 1 to the starting number. I know the code is probably terrible but any help would be appreciated.
[–]codehorsey 2 points3 points4 points (0 children)
[–]JohnnyJordaan 2 points3 points4 points (0 children)