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 1, Problem 5PE
Program Plan Intro
chaos program
Program Plan:
- Declare a main function. Inside the main function,
- Print the statement
- Get the value from the user
- Traverse the value of “x” through “for” loop until “x” reaches “20”.
- Evaluate the value of “x”.
- Print the value of “x”.
- Call the main function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that will print asterisks in the shape of a diamond. The height of the diamond will depend on the value entered by the user. That value MUST be greater than 0, and it MUST be odd. To make sure that the value is correct, you will validate the value once the user has entered it using a validation loop. Then you will print out a diamond in the pattern demonstrated in the sample execution. Remember that the height will vary based on the user input.
Write a program that will print the message “I love computer science” 12 times. Use a while loop.
Instead of printing 12 times, ask the user how many times the message should be printed. You will need to declare a variable to store the user’s response and use that variable to control the loop.
Number each line in the output, and add a message at the end of the loop that says how many times the message was printed. So if the user enters 3, your program should print this:
_____________________________________
1 I love computer science
2 I love computer science
3 I love computer science
This message is printed 3 times.
Write a program in Python that sums a series of (positive) integers entered by the user, excluding all numbers that are greater than 100. We are going to use a sentinel value (also known as a flag value) to control the loop. If the user wants to quit summing up numbers, the user will enter a (-1). The first line should print out a title that says something like “Practice 3: summing positive values entered by the user that are less than 100”. For this practice you only can use while loop as you don’t know how many numbers the user wants to enter. A sample output is below.
Chapter 1 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 1 - Prob. 1TFCh. 1 - Prob. 2TFCh. 1 - Prob. 3TFCh. 1 - Prob. 4TFCh. 1 - Prob. 5TFCh. 1 - Prob. 6TFCh. 1 - Prob. 7TFCh. 1 - Prob. 8TFCh. 1 - Prob. 9TFCh. 1 - Prob. 10TF
Ch. 1 - Prob. 1MCCh. 1 - Prob. 2MCCh. 1 - Prob. 3MCCh. 1 - Prob. 4MCCh. 1 - Prob. 5MCCh. 1 - Prob. 6MCCh. 1 - Prob. 7MCCh. 1 - Prob. 8MCCh. 1 - Prob. 9MCCh. 1 - Prob. 10MCCh. 1 - Prob. 1DCh. 1 - Prob. 2DCh. 1 - Prob. 3DCh. 1 - Prob. 4DCh. 1 - Prob. 5DCh. 1 - Prob. 1PECh. 1 - Prob. 2PECh. 1 - Prob. 3PECh. 1 - Prob. 4PECh. 1 - Prob. 5PECh. 1 - Prob. 7PE
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
- You will select one of the problems below and create a program that uses nested selections to solve the problem.Do not use Boolean operators. Write a program that reads three edges for a triangle and computes the perimeter if the input is valid. Otherwise, display that the input is invalid. The input is valid if the sum of every pair of two edges is greater than the remaining edge.arrow_forwardWrite a program in Python, in which the user can enter any number of positive and negative integer values, and then we display the total number of positive values entered and the total number of negative values entered. We are going to use a sentinel value (also known as a flag value) to control the loop. If the user wants to quit counting up positive and negative numbers, the user will enter a (q). The first line should print out a title that says something like “Practice 4: Counting the number of positive and negative values entered by the user”.arrow_forwardThis is a java assignment. I have attached it in the image file.arrow_forward
- Write a program that asks the user for a positive integer value and that uses a loop to validate the input. The program should then use a second loop to compute the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, … 50.arrow_forwardPrint numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3arrow_forwardWrite a program that asks the user to enter an integer number and checks whether the number is prime or not. Hint: A prime number (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 . . . ) is a natural number greater than 1 that has no positive divisors other than 1 and itself. To check if a number N is prime, divide it in a loop from 2 to N-1 for remainder. If remainder is never 0, then N is prime. For example, 23 and 47 are prime, but 12 and 27 are not.arrow_forward
- Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40:20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks".Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.arrow_forwardn is an integer variable.Write a while loop that prints integer numbers starting with n and dividing the number to 4 each time, while the new number is greater than 0.(Example: If n is 2077, it will print 2077 519 129 ...)Write only the statements to perform the above explained task, nothing else.Use while loop, don't use for loop.arrow_forwardWrite a program to simulate how a for loop works with the range. The input to your program are two integers start and stop. Check that the second integer stop is not less than or equal to the start. If the second integer stop is less than the first start, then see the example output below. Otherwise, (if the stop is less than the start) proceed with the rest of the program. Output the value of the start and keep subsequently incrementing it by 5 as long as the value is less than the stop. Input (1) : 20 5 --> the output is: There won't be any output sequence if the second integer is less than or the same as the first. input (2) :-15 10 the output is: -15 -10 -5 0 5 Use the if/else statements to run a preliminary check of the input before taking other actions Use the print() statement inside the loop Provide the end argument to the print() to correctly generate the output sequencearrow_forward
- Write a loop that iterates exactly ten times. With each iteration it should ask the user to enter a number, and keep a running total of all numbers entered. When the loop is finished, display the total sum (float) and the average of the 10 numbers (float).arrow_forwardWrite a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates, it prints out the sum of all the even integers read and the sum of all the odd integers read(The two sums are separated by a space). Declare any variables that are needed.arrow_forwardFactorial of a number n is denoted as n! And the value of n! Is: 1*2*3... (n-1)*n. Create Java Program to find factorial of a positive integer number using the following Loops: a. for Loop b. while loop Valid input is less than or equal to 15 (Input <= 15) only, otherwise the input is Invalid. Please see the attached image for the Output format. Please don't answer my question if you don't read the instructions carefully, this is my last question so please cooperate.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY