I know this is a simple answer, but in the below code, how do I make it only produce the final answer and not a list of each step? If you see below, the program produces the correct answer to the program I wrote but I don't want it to keep saying "the sum of cubes....". I just want it to provide the final answer. Also, how would I make the line input the chosen number instead of "n". So for example, if a user enters the number 5 into the initial prompt, how do I make the output text reflect the input provided by the user?
Ignore the "size" entries- I messed up the text upon import and now I can't get those to go away.
Result of using the number 3 (correct):
Ignore the "size" entries- I messed up the text upon import and now I can't get those to go away.
1 2 3 4 5 6 7 8 9 |
def main(): print ( "This program calculates the sum of the cubes of the first n natural numbers" ) natn = eval ( input ( "Enter the ending natural number: " )) for natn in range ( 1 , natn + 1 ): natnsum = natn * * 2 * (natn + 1 ) * * 2 / 4 print ( "The sum of the cubes of the first n natural numbers is" , natnsum, "." ) main() |
Output:This program calculates the sum of the cubes of the first n natural numbers
Enter the ending natural number: 3
The sum of the cubes of the first n natural numbers is 1.0 .
The sum of the cubes of the first n natural numbers is 9.0 .
The sum of the cubes of the first n natural numbers is 36.0 .
Process finished with exit code 0
-Thanks