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
Concept explainers
Question
Chapter 3, Problem 15PE
Program Plan Intro
Summing the terms
- Import “math” library.
- Define the main function.
- Get the number of terms to be summed from the user and store it in a variable “n”.
- Declare required variables.
- Loop for “n” times.
- Calculate the value of “sumN”, “denominator”, and “number”.
- Print the value of “sumN”.
- Print the value of “abs(math.pi - sumN)”
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
i need the answer quickly
Write a program which repeatedly reads several people's height numbers in cm(centimeter) until the user enters "done". Once "done" is
entered, print out the max, min, and average of the height numbers. Correct height data should be number between 50cm and 250cm. If the
user enters number out of the range, or anything other than a number, detect the mistake and print an error message and skip to the next
number.
Sample input and output:
Enter a height: 300
Invalid input
Enter a height: 10
Invalid input
Enter a height: 200
Enter a height: good
Invalid input
Enter a height: 180
Enter a height: 165
Enter a height: done
Max: 200.0
Min: 165.0
Average: 181.67
Code the follow.
Chapter 3 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
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
- Write a program that asks the user to enter an integer consisting of 4 digits only, and check how many even number (s) is in its digits. Sample run 1: Enter a number with four digits: 547 Your number is less than 4 digits. Sample Run 2: Enter a number with four digits: 56597 Your number is more than 4 digits. Sample Run 3: Enter a number with four digits: 5678 There's 2 even number (s). Solution + Screenshot of the run:arrow_forwardI wrote the following program for this problem and it works, but is too slow on big numbers. How could i make it faster? Problem: We want to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, we can represent 121 as 121=111+11+–1. Help us to find the least number of digits 1 in such sum. Input: The first line of the input contains integer n (1 ≤ n < 1015). Output: Print expected minimal number of digits 1. (ex. input:121, output:6) My solution: import java.util.Scanner; public class Main { staticlong[] en=newlong[]{1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111, 11111111111L,111111111111L,1111111111111L,11111111111111L,111111111111111L,1111111111111111L}; public static void main(String[] args){ Scanner scanner =new Scanner(System.in); System.out.println(rekisto(scanner.nextLong())); } static long rekisto(long s){ if(s==0){ return 0; } int dolzina…arrow_forwardT can be approximated by using the following infinite series: +-+...) Write a program that prints out two versions of the approximation one that goes out to a denominator of 13 and one that goes out of a denominator of 15. T=4 1 3 5 7 9 Note you will want to use 1.0 for your numerators. In my code I used a decimal version for all of these integers.arrow_forward
- Write a program that will determine how many of a set of 10 numbers are even and how many are odd. a. Read in one number at a time. b. Compute and display the number of even integers and the number of odd integers. Hint: You can use the modulus operator (%) to determine if each integer is even or od. Your output should look like this: Enter integer: 2 Enter integer: 4 Enter integer: 3 Enter integer: 5 Enter integer: 6 Enter integer: 4 Enter integer: 77 Enter integer: 5 Enter integer: 89 Enter integer: 45 There are even numbers in the list 6 odd numbers in the list 4 There are >>>arrow_forwardIn this task, you are required to write a code which takes as an input an angle [0°, 90°] in radians and returns the approximate value of the cosine of this angle. The code will also take as an input the number of terms to be used to approximate the result. We will use the Maclaurin series of cos(x) to approximate the result. The series is given by: cos(x) -1"x2 Ln =0 (2n!) but for practical reasons, we will not use infinite terms but k terms where k is input by the user: cos(x) = -1"2 Ln =0 (2n!) So, for example, to calculate the cosine for 60° (1.04667 radians) using five terms, the approximation will be: 1- 1.04667? 2! 1.04667 8! 1.046674 1.04667 = 0.50046 4! 6! • The program should at most handle 15 terms (to avoid overflows due to factorial), otherwise the program outputs Invalid • There should be at least three terms used in the approximation, otherwise the program outputs Invalid • If the number of terms is negative, the programs corrects it automatically to positive. I/0…arrow_forwardWrite a program that reads a four-digit integer, such as 2014, and then displays it, one digit per line in reverse order, like so: 4 1 0 2 Your prompt should tell the user to enter a four-digit integer. You can then assume that the user follows directions. (Hint: Use the division andm remainder operators.)arrow_forward
- IN PYTHON: To estimate pi, generate a series of x, y random pairs, where x and y are in the range -1 to 1. Count the number of points that are at a distance less than or equal to 1. The number of points inside the circle of radius 1 divided by the number of points generated will give pi/4. Use your program to calculate pi Draw a blue square of size 2, in the x-y plane, centered at the origin. Generate a sphere at each (x,y) point. For each point generate a white sphere if the (x,y) point is greater than distance 1 from the origin, and a yellow sphere if the point’s distance from the origin is less than or equal to 1.arrow_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 will ask how many number of integers to input (n) and it will read in integer's nth times. Then the program will display the all positive integers and all negative integers and its sum, separately. Refer sample run below. Sample Run: Enter number of integers to be entered: 4 Enter integer 1:2 Enter integer 2: -1 Enter integer 3: -6 Enter integer 4: 13 The following positive integer/s: 2, 13 The sum of the positive integers: 15 The following negative integer/s: -1, -6 The sum of the negative integers: -7arrow_forward
- 1. The following Little Man program is supposed to add two input numbers, subtract a third input number from the sum, and output the result, i.e., OUT = IN1 + IN2 – IN3 Mailbox Mnemonic Code Numeric Code 00 IN 901 01 STO 90 390 02 IN 901 03 ADD 90 190 04 STO 90 390 05 IN 901 06 SUB 90 OUT 290 07 902 08 СОВ 000 What is wrong with this program? Modify the program so that it produces the correct result. 2. Write a Little Man program that accepts three values as input and produces the largest of the three as output.arrow_forwardWrite a program that first reads the value n, which is the number of numbers to average. It should then read the n positive (float) numbers, average them, and display the average. ENTRYAn integer n and then the n floating numbers EXIT The average of the n numbers read. Example of program execution: Input 3 Entry 2.5 Entry 3.8 Entry 4.6 Output3.633333333333333arrow_forwardWrite a program that generates a plate number based on the user's answer to the following questions: 1. What is your favorite color of the rainbow (ROYGVIB)? a. Use the first letter of the chosen color as the first character of the plate number. b. Display "Invalid Input" and ask the user to re-enter his/her answer if the answer is not a valid color of the rainbow. 2. What is your month of birth? a. Use the last letter of the month as the second character of the plate number. b. Display "Invalid Input" and ask the user to re-enter his/her answer if the answer is not a valid month. 3. What is your first name? a. Use the third letter of the first name as the third character of the plate number. No need to include the second name if you have a second name. Make sure to use "cout" and "cin" to collect the necessary inputs from the user. For the number section: 1. Ask the user his/her age and use the age as the first and second digits of the plate number. a. Display "Invalid Input" and ask…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
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY