write a program that gets an integer value from the user and calculates the following: 1) additive persistence and the corresponding additive root 2) multiplicative persistence and the corresponding multiplicative root You will continue to do so until the user quits.
1. The beginning integer is 1234 2. Sum its digits is 1+2+3+4 = 10 3. The integer is now 10 4. The sum of its digits is 1 + 0 = 1 5. The integer is 1. When the value reaches a single digit, we are finished.
Hint: use the modulo operator.
which language is this ?
how is it ?
What?
how can I apply it with different functions I got this big program but how can I generalize it n1=0 n2=0 n3=0 n4=0 s=0 n=int(input('input is your number:')) n1=n%10 n2=(n%100-n1)/10 n3=(n%1000-n%100)/100 n4=(n%10000-n%1000)/1000 s=n1+n2+n3+n4 p=n1*n2*n3*n4 if s%10==s: print('the sum of the digits is :',s,'and the additive persistence is:1') else: n1=s%10 n2=(s%100-n1)/10 n3=(s%1000-s%100)/100 n4=(s%10000-s%1000)/1000 s=n1+n2 p=n1*n2*n3 if p%100==s print('the product of the digits is :',p,'and the multiplicative persistence is:1')
use loops
how
can u show me how @dust7
I'm not sure I understand your problem specification, could you be more clear about it? - take input from user - if input is 1, return -else... (add digits?)
ok I've don it thanks ..
Join our real-time social learning platform and learn together with your friends!