Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Question
Chapter 6, Problem 4PE
Program Plan Intro
Calculate the sum of first n natural numbers and sum of cubes of first n natural numbers
Program plan:
- The function named “sumN()” is defined and inside the “sumN()”,
- Declare and initialize the variable named “fact” and store the calculated area value in it.
- Initialize a for loop which ranges from 1 to -1
- Add the value of factor to fact.
- Return the value stored in the “fact” variable.
- The function named “sumNCubes()” is defined and inside the “sumNCubes()”,
- Declare and initialize the variable named “cube” and store the calculated area value in it.
- Initialize a for loop which ranges from 1 to -1
- Multiply the value of factor with 3 and then add that value to “cube”.
- Return the value stored in the “cube” variable.
- In the “main()” function,
- Generate a prompt to take the user input.
- Call the method named “sumN()” with user input as the argument.
- Call the method named “sumNCubes()” with user input as the argument.
- Print the output statement and output value.
- Call the function “main()”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write definitions for the following two functions:sumN (n) returns the sum of the first n natural numbers.sumNCubes (n) returns the sum of the cubes of the first n natural numbers.Then use these functions in a program that prompts a user for an n andprints out the sum of the first n natural numbers and the sum of the cubesof the first n natural numbers.
Python question
Write a function that checks whether an integer is an even digit or an odd digit integer using the following header:
int getType(int n)
Chapter 6 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 6 - Prob. 1TFCh. 6 - Prob. 2TFCh. 6 - Prob. 3TFCh. 6 - Prob. 4TFCh. 6 - Prob. 5TFCh. 6 - Prob. 6TFCh. 6 - Prob. 7TFCh. 6 - Prob. 8TFCh. 6 - Prob. 9TFCh. 6 - Prob. 10TF
Ch. 6 - Prob. 1MCCh. 6 - Prob. 2MCCh. 6 - Prob. 3MCCh. 6 - Prob. 4MCCh. 6 - Prob. 5MCCh. 6 - Prob. 6MCCh. 6 - Prob. 7MCCh. 6 - Prob. 8MCCh. 6 - Prob. 9MCCh. 6 - Prob. 10MCCh. 6 - Prob. 1DCh. 6 - Prob. 2DCh. 6 - Prob. 3DCh. 6 - Prob. 4DCh. 6 - Prob. 5DCh. 6 - Prob. 1PECh. 6 - Prob. 2PECh. 6 - Prob. 3PECh. 6 - Prob. 4PECh. 6 - Prob. 5PECh. 6 - Prob. 6PECh. 6 - Prob. 7PECh. 6 - Prob. 8PECh. 6 - Prob. 9PECh. 6 - Prob. 10PECh. 6 - Prob. 11PECh. 6 - Prob. 12PECh. 6 - Prob. 13PECh. 6 - Prob. 14PECh. 6 - Prob. 16PECh. 6 - Prob. 17PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Complete the function that calculates the sum of the first n+1 terms of the geometric series a, ar, ar² ar³, art Note that the series begins with a and the last term is ar", in total there are n+1 terms. # complete the function given the variables a,r,n and return the value as series_sum. def sum geometric_series (a,r,n): # YOUR CODE HERE return series_sum ... arr print (sum_geometric_series (4.0, 5, 10))arrow_forwardComplete the function that calculates the sum of the first n+1 terms of the geometric series a, ar, ar² ar³, arª ….. arn Note that the series begins with a and the last term is ar", in total there are n+1 terms. 1: # complete the function given the #variables a,r,n and return the value as series_sum. def sum geometric_series(a,r,n): # YOUR CODE HERE return series_sum print (sum_geometric_series (4.0, 5, 10))arrow_forwardComplete the function that calculates the sum of the first n+1 terms of the geometric series a, ar, ar² ar³, ar4 . note that the series begins with a and the last term is ar", in total there are n+1 terms. ar" ... [ ]: # complete the function given the variables a,r,n and return the value as series_sum. def sum_geometric_series(a,r,n): # your code here return series_sumarrow_forward
- Write a program that calculates the Euclidean distance and the Manhattan or taxicabdistance between two two-dimensional points. Make sure you 1) use a point structureto store the points (see above), 2) use functions to calculate the two distances and3) ask the user for the point data. The Euclidean distance is calculated using thePythagorean Theorem for (points (x1,y1),and (x2, y2):euclidean = ( x1-x2)^2 + ( y1-y2)^2And the Manhattan distance is calculated as:manhattan = | x1-x2 | + | y1-y2 |arrow_forwardIn pythonarrow_forwardWhat does this function using to? int max(int a , int b) if(a > b) return a; else return b; } returns the maximum of two integer numbers returns the minimum of two integer numbers returns the maximum of an floating point numbers returns the minimum of two floating point numbersarrow_forward
- good stat ofl them ii days. You need to upload your solutions in a single python file (assl.py) to the link on MS Teams. Part 1 Add this comment: # Ass 1: Part 1 Write a program that declares a function called draw Star which receives an integer value as a parameter, and draws a number of stars equal to the received integer. Samplel: Please enter the number of stars: 5 The shape is: **** Sample2: Please enter the number of stars: 3 The shape 15 *** Part 2 Add this comment: Ass 1: Part 2 Write a program that summation of even ni "nd M then prints the 3.9 nclud d if were even of 3arrow_forwardA triangular number is defined as m(m + 1)/2 for m = 1, 2, c , and so on. Therefore, the first few numbers are 1, 5, 12, 22, . . . . Write a function with the following header that returns a triangular number: int getTriangularNumber(int n) Write a test program that uses this function to display the first 75 triangular numbers with 5 numbers on each line.arrow_forwardQ4: the volume of a cylinder is given by the formula: V=n r2L Where r is the cylinder's radius and L is its length. Using the above formula; write a program that uses a function which accepts a cylinder's radius and length as parameters and returns its volume.arrow_forward
- Complete the get_sum_of_evens (lower_bound, upper_bound) function that takes two integer parameters, lower bound and upper bound. The function returns the sum of all the even numbers between the two bounds, both included, passed to the function. You can assume that lower bound will always be smaller than or equal to upper_bound. For example: Test result get sum_of_evens (2, 4) print("The sum of all even numbers are:", result) print (get_sum_of_evens (9, 17)) Result The sum of all even numbers are: 6 52arrow_forwardWrite a function that will display the reverse of the number.arrow_forwardthat takes 3 integers as an input from the user and display them in ascending order (slai y ). For example, if the input is 2, 3 and 1, this program should display 1, 2 and Write program a 3. To resolve this problem, you should write 3 void functions: inputNumbers, sortNumber and displayNumbers. inputNumbers : the aim of this function to read 3 numbers from the user. sortNumber : the aim of this function to sort three numbers. displayNumbers : print the results. easy codearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Python - bracket parenthesis and braces; Author: MicroNG;https://www.youtube.com/watch?v=X5b7CtABvrk;License: Standard Youtube License