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 1, Problem 3PE
Program Plan Intro
chaos
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 “10”.
- 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
Matlab:
Please write the codes on matlab, I don't want a manual solution.You can see pic.
Write a MATLAB code to create a matrix of random numbers with 4 rows and three columns. Then use nested loops and IF to put zero instead of the numbers that are greater than 0.5.
Pick a number, any number (actually, make it a positive integer). Now, let's play a game. If your number is
even, divide it by 2. If it is odd, multiply it by 3 and add 1. Repeat this process with your new number.
Repeat over and over again. Lothar Collatz in 1937 guessed that this process will always eventually end at
the number 1. Write a Matlab function file that takes an input n (assume the user enters a positive integer)
and runs through the Collatz process until a 1 is reached. The function should output count, the number
of iterations necessary to reach 1. As a test, your code should report that 63 iterations are necessary if we
start with the number 2020.
Chapter 1 Solutions
Python Programming: An Introduction to Computer Science
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
- (Program) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters, such as zerocount, onecount, twocount, and so forth, to 0. Then generate a large number of pseudorandom integers between 0 and 9. Each time 0 occurs, increment zerocount; when 1 occurs, increment onecount; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of time they occurred.arrow_forwardCan you solve in MATLAB? Please...arrow_forwardUse the cubicSpline module to write programs that interpolate between a given data point with a cubic spline. The program must be able to evaluate the interpolant for more than one x value. As a test, use the data points specified in the previous Example and calculate the interpolants at x = 1.5 and x = 4.5 (due to symmetry, these values must be the same) import numpy as np from cubicSpline import * xData = np.array([1,2,3,4,5], float) yData = np.array([0,1,0,1,0], float) k = curvatures (xData, yData) while True: try: x = eval(input("\nx ==> ")) except SyntaxError: break print("y=", evalSpline (xData, yData, k, x)) input ("Done. Press return to exit") Exercise Fix the Cubic Spline Program There is an error in the Cubic Spline program, fix it and evaluate the values of x 1/2 = 1.5 and x = 4.5, where the results of both values must be the same.arrow_forward
- There are many algorithms presented in this text that would lend themselves to beincluded as subprograms in the utils.asm file. Implement some or all of the followinginto the utils.asm file, properly documenting them, and include programs to test them.a. NOR subprogram - take two input parameters, and return the NOR operation onthose two parameter.b. NAND- take two input parameters, and return the NAND operation on those twoparameter.c. NOT- take one input parameters, and return the NOT operation on that parameter.d. Mult4 - take an input parameter, and return that parameter multiplied by 4using only shift and add operations.e. Mult10 - take an input parameter, and return that parameter multiplied by 10using only shift and add operations.f. Swap- take two input parameters, swap them using only the XOR operation.g. RightCircularShift - take an input parameter, and return two values. The firstis the value that has been shifted 1 bit using a right circular shift, and the second isthe…arrow_forwardThe following question requires code in MATLAB.arrow_forwardPls help me to write a c++ programarrow_forward
- Write a function that determines the type of its input variable and converts it into a character array, if it is numeric, or displays an error message if it is not numeric or character array. Please answer with code in MATLAB, thanks!arrow_forwardWrite a short MATLAB function to find out whether a given number (up to 1,000,000) is a prime number. The function should return true or false. Bear in mind that 1 is not considered a prime number. (Hint: Divide the number (K) by all integers from 2 to K-1. Check the remainders for 0s.) Subsequently, apply this function to list all prime numbers between 1 and 100.arrow_forwardthis will be a code in matlab, thank youarrow_forward
- f(x) = 1/(1 + 25.a?) This is a somewhat famous function in numerical analysis because it displays interesting behavior when approximated using polynomial interpolation on uniformly spaced nodes. You are going write your own code for polynomial interpolation and investigate the accuracy of two approximations. Task: Do the following: 1. Write a function that takes an array containing n+1 distinct points and returns the coefficients a, k 0, 1, .. . , n for the Newton form of the interpolating polynomial for an arbitrary function. You can pass in either the function f(x) or an array of function values at the points. 2. Write a function that takes the Newton coefficients of the polynomial and a point r and evaluates P,(x). This should be the nested product form that is similar to Horner's method. 3. Write a program that calls your two functions to compute the interpolating polynomial for the specific function f(x) given above and does the following: (a) Using the 21 uniformly spaced nodes…arrow_forwardI have been working for so long on this code . But I'm not very good at MATLAB. I need help for this code .This will help me to learn better .arrow_forwardConsider the following Matlab expressions (you can assume that all involved variables exist in Workspace): Expression a: y = 1.5 * power + log(Power) - x; Expression b: y = 1.5 * Power + log(power) - x; You execute one of those expressions. The value of y will always (no matter what values are assigned to variables involved) end up being the same regardless whether you run expression a or b. True or false? a) True b) Falsearrow_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
The Top Down Approach to Software Development; Author: Christopher Kalodikis;https://www.youtube.com/watch?v=v9M8LA2uM48;License: Standard YouTube License, CC-BY