Question
A perfect digital invariant (PDI) is a number that is the sum of its own digits each raised to a given power, p . For
A perfect digital invariant (PDI) is a number that is the sum of its own digits each raised to a given power,
p
. For example, the number 4150 with
p=5
is a PDI because
4^(5)+1^(5)+5^(5)+0^(5)=4150
. Write a Python program in the box below that takes in a four (4) digit integer and a given power from the user and prints out if the number is a PDI or not. You may assume the user always enters a four (4) digit integer, however it is possible that the leading digit is zero (0). Do NOT use lists, string slicing, or the sort () and sorted () functions. Use four (4) spaces in place of one (1) tab. You do not have to use any special output formatting. DO NOT USE PYTHON. Practice typing your code without a code editor (as you would on an exam). This question will be graded manually and partial credit will be generous. Don't forget to comment your code!\ Do not forget to put comments in your code!!!!\ Hints:\ For a three digit number, number // 100 gives you the first digit of number (the hundreds place)\ For a three digit number, number
%100
gives you the second and third digits of number (the tens and ones places)\ Example output using input 4150 and 5 :\ Enter a 4-digit integer: 4150\ Enter the power: 5\ 4150 with given power 5 is a PDI\ Example output using input 0102 and 3:\ Enter a 4-digit integer: 0102\ Enter the power: 3\ 102 with given power 3 is NOT a PDI
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started