Python Programming: An Introduction to Computer Science
3rd Edition
ISBN: 9781590282779
Author: John Zelle
Publisher: Franklin Beedle & Associates
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 11PE
Program Plan Intro
Sum of first n natural numbers
- Define the main function.
- Get the value of “n” from the user.
- Declare a variable “sum” and assign 0 to it.
- Loop from 0 through n.
- Calculate the value of sum and store it in a variable “sum”.
- Print the value of “sum”.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Write a program that calculates the sum of all positive integers less than or equal to a given number N.
A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is
Area = ( n * s2 ) / (4 * tan( π/n)
Here, s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area.
Code in Python
Write a program to find the 6-th Monisen number. Classic Programming Question: find the n-th Monisen number. A number M is a Monisen number if M=2**P-1 and both M and P are prime numbers. For example, if P=5, M=2**P-1=31, 5 and 31 are both prime numbers, so 31 is a Monisen number. Put the 6-th Monisen number into a single text file and submit online
Chapter 3 Solutions
Python Programming: An Introduction to Computer Science
Ch. 3 - Prob. 1TFCh. 3 - Prob. 2TFCh. 3 - Prob. 3TFCh. 3 - Prob. 4TFCh. 3 - Prob. 5TFCh. 3 - Prob. 6TFCh. 3 - Prob. 7TFCh. 3 - Prob. 8TFCh. 3 - Prob. 9TFCh. 3 - Prob. 10TF
Ch. 3 - Prob. 1MCCh. 3 - Prob. 2MCCh. 3 - Prob. 3MCCh. 3 - Prob. 4MCCh. 3 - Prob. 5MCCh. 3 - Prob. 6MCCh. 3 - Prob. 7MCCh. 3 - Prob. 8MCCh. 3 - Prob. 9MCCh. 3 - Prob. 10MCCh. 3 - Prob. 1DCh. 3 - Prob. 3DCh. 3 - Prob. 4DCh. 3 - Prob. 6DCh. 3 - Prob. 1PECh. 3 - Prob. 2PECh. 3 - Prob. 3PECh. 3 - Prob. 4PECh. 3 - Prob. 5PECh. 3 - Prob. 6PECh. 3 - Prob. 7PECh. 3 - Prob. 8PECh. 3 - Prob. 9PECh. 3 - Prob. 10PECh. 3 - Prob. 11PECh. 3 - Prob. 12PECh. 3 - Prob. 13PECh. 3 - Prob. 14PECh. 3 - Prob. 15PECh. 3 - Prob. 16PECh. 3 - 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
- helparrow_forwardWrite a program that reads in three integers and then determines and prints the largest and the smallest integers in the group. Use only the programming techniques you have learned in this chapter.arrow_forwardWrite a program that reads 6 integers and displays the largest and the smallest amongst those integers.arrow_forward
- Python Programming A positive whole number n>2 is prime if no number between 2 and sqrt(n)(inclusive) evenly divides n. Write a program that accepts a values of n as input and determines if the value is prime. If n is not prime, your program should quit as soon as it finds a value that evenly divides n.arrow_forwardwrite a program in python Write a program that will allow a student to enter their name and then ask them to solve 10 mathematical equations. The program should display two random numbers that are to be added, such as: 247 + 129 The program should allow the student to enter the answer. The program should then display whether their answer was right or wrong, and accumulate the right values. After the 10 questions are asked, calculate the average that was correct. Then display the student name, the number correct, and the average correct in both decimal and percentage format. In addition to any system functions you may use, you might consider the following functions: A function that allows the student to enter their name. A function that gets two random numbers, anywhere from 1 to 500. A function that displays the equation and asks the user to enter their answer. A function that checks to see if the answer is correct and accumulates the number correct. A function that calculates the…arrow_forwardWrite a program that finds the sum, difference, and product of 2 given numbers.arrow_forward
- Write a program that reads two integers (M and N) from user until user provide 0 for M and N. The program should calculate two sums: sum of All ODD integers, and sum of All EVEN integers between M and N. In the output, the program should print both the sums (sum of even andodd integers)arrow_forwardplease helparrow_forwardThe GCD (Greatest Common Divisor) of two numbers is the largest positive integer number that divides both the numbers without leaving any remainder. Write a program that prompts the user to enter two positive integers and computes their GCD. For example. GCD of 30 and 45 is 15. Sample Run 1: Enter two integers: 30 45 GCD of 30 and 45 is 15 Sample Run 2: Enter two integers: 55 121 GCD of 55 and 121 is 11arrow_forward
- Write a program that calculates the equivalent resistance of a circuit. n electrical resistors with resistance values R1, R2,.., Rn are said to be connected in parallel if the same voltage is applied across each. Their equivalent resistance Reg is related to the values R1, R2, ..., Rn by: 1 1 1 1 + +...+ R R R, R. "eq Write a program that prompts the user to enter the resistance of n resistors. The user should be prompted continuously by using a while loop until a zero or negative value is entered (the program should count the number of resistors n entered by the user and store the values in an array). Use another separate loop to print the resistance values entered by the user and the equivalent resistance Reg. Test your program with R1= 1 kn, R2= 2 kn, R3= 4 kQ and R4= 8 kQ.arrow_forwardWrite a program that reads 11 integers, compares eachinteger with the 11th integer, and displays whether the integers are “greater”,“smaller”, or “equal” to the 11th integer.arrow_forwardWrite a program that reads some integers between 1 and 100 and counts the occurrences of each.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY