Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sum1= n+nn+nnn+…n^r.
Eg:5+55+555=615



Sum2=n+(n*n)+(n*n*n)+…n^r.
Eg:5+(5*5)+(5*5*5)=155

What I have tried:

n=int(input("Enter a number n: "))
temp=str(n)
t1=temp+temp
t2=temp+temp+temp
comp=n+int(t1)+int(t2)
print("The value is:",comp)
Posted
Updated 14-Aug-18 6:22am
Comments
Patrice T 14-Aug-18 12:50pm    
What is the question?

Case 1:
Enter a number n: 5
The value is: 615
 
Case 2:
Enter a number n: 20
The value is: 204060
 
Share this answer
 
Why are you converting an integer to a string to do the calculation? You already used the int function to get the input as a numeric value.

Your program should accept the value for n first, as an integer.
It should then accept the value for r and use those two numbers to perform the calculation.
Your code does not go far enough, and does not allow for the value of r.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900