Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Spyder is the python software used or use any python programming to solve. LAB 5 CS 112, Spring 2021 Part 1: Due in Gradescope by
Spyder is the python software used or use any python programming to solve.
LAB 5 CS 112, Spring 2021 Part 1: Due in Gradescope by 4:30pm You will er ate and submit a single script including each of the following function definitions (sce the assigument page in Canvas for a starter script). Remember to pay close attention to whether your result should be returned or print ed. You should print enough test cases below each of your function definitions to be reasonably sure it works for all types of inputs as described in the problem. Your test cases should be different from any of the examples provided in the problem. 1. Use a while loop to write a function print_sequence that takes as input a positive integer n and prints in sunce that starts with a wave creates the next term by following the rules . If the vil term is even the divide it lw 2 and subtract 1 to get the next term. Ifihe previous terni is add, then niply it by 1 and subtract 2 to get the next term. The first time that one of these terms a value of 1 or lower, and the sequence there For unple, print_sequence (3) should print them 3. 10. 4. 1. ad print_sequence (5) should print the terus 5 18. 8.3. 10. 4 and 1 2. Newton's method i be proximate the hot of sumber by taking lir a value of 1 or lower, end the sequence there. For example, print_sequence (3) should print the terms 3, 10, 4, and 1, and print_sequence(5) should print the terms 5, 18, 8, 3, 10, 4, and 1. 2. Newton's method can be used to approximate the cube root of a mimber a by taking a as the first approximation, and iterating the equation below to get progressively better approximations: 27old + a/c 3 Use a while loop to write a function newtons_cbrt that takes as input a mumber a and a number error, and that uses the equation above to find an approximation to ya. The function should return the first approximation whose difference from the previous approxi- mation dips below error. For example, newtons_cbrt (73, 0.1) (that is, where a - 73 and error 0.1) should return 4.17934404720554 . Inew 3. Write a friction avoid_char that takes as input a string word and a letter char , and that traverses through word, printing cach character in word except those that are equal Lo char For example, avoid char('hello', '10 should print the letters h. e. and o. And avoid char( abracadabra', a'should print the letters b. r. c. d bud 1. Write a function right justify that takes an input string (we length in less than 60) and returns to Wiring an inserund enough spaces the left of the input string so 1 that it now has length 60. For example, right_justify('hello') should return hello and right_justify (Christian Brothers University') should return Christian Brothers University Both these outputs are strings of length 60Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started