Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Read Chapter 12
Recursive Lines
Write a recursive function that accepts an integer argument, n. The function should display n lines of asterisks on the screen, with the first line showing 1 asterisk, the second line showing 2 asterisks, up to the middle line which shows n asterisks. You will then continue to print less stars until your last line of one asterisk.
With an input of 3 your output should look like below. You will need to wind the stack to print up to your largest line. You will print the last set of lines as you unwind the stack or as you come out of your recursion.
*
**
***
**
*
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
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
- Consider the following function that takes two positive integers x and y as its input parameters. This function is supposed to be a recursive function but it is not. Which option best describes the reason? |def recursive_function2(x, y): if x < ® and y < ®: return False else: result - sum([x, y]) result +- 10 return rec_function2(x-1, y-1) A recursive function must call itself. This function calls a function with a different name. There is nothing wrong with this recursive function. ) This function does not import any module to call the function sum() O A recursive function can only call itself and must not call any other function e.g., sum()arrow_forwardPlease only do rec_sum_digits function in python using only recursive and no looparrow_forwardpython3 Write a recursive function called is_palindrome(string) that takes a string parameter and checks if it is a palindrome ignoring the spaces, if any, and returns True/False. Sample output:>>> print(is_palindrome("never odd or even"))True>>> print(is_palindrome("step on no pets"))Truearrow_forward
- For each function, describe what it actually does when called with a string argument. If it does not correctly check for lowercase letters, give an example argument that produces incorrect results, and describe why the result is incorrect. # 1 def any_lowercase1(s): for c in s: if c.islower(): return True else: return False # 2 def any_lowercase2(s): for c in s: if 'c'.islower(): return 'True' else: return 'False' # 3 def any_lowercase3(s): for c in s: flag = c.islower() return flag # 4 def any_lowercase4(s): flag = False for c in s: flag = flag or c.islower() return flag # 5 def any_lowercase5(s): for c in s: if not c.islower(): return False return True The code and its output must be explained technically whenever asked. The explanation can be provided before or after the code, or in the form of code comments within…arrow_forwardPart (a) Write a python function that computes the binomial coefficient ("). The function should return the correct answer for any positive integer n and k where k=m pass Part (c) Suppose that the number of people in the trial is 100. Then: • Plot a curve that shows how the probability of type 1 error changes with the choice of m, for m = 1,...n assuming that the null hypothesis holds (in red), • On the same picture, plot the probability of type 2 error vs the value of m in the case in which the new drug is effective with proability 0.68 (in blue). You can plot the two curves using matplotlib.pyplot. You can select the color by passing color='r' or color='b' to the plt.plot() function. [4]: n - 100 # your code here def plot_curve (): pass [5]: plot_curve() Part (d) Based on the picture above, what value of m do you think would be suitable to keep both type 1 and type 2 error small at the same time? (You may assume that the company claims the new drug has 68% accuracy) [6]: # your…arrow_forwardplease code in python Write a recursive function to add a positive integer b to another number a, add(a, b), where only the unit 1 can be added, For example add(5, 9) will return 14. The pseudocode is: # Base case: if b is 1, you can just return a + 1 # General case: otherwise, return the sum of 1 and what is returned by adding a and b - 1.arrow_forward
- main.py Load default template.. 1 # TODO: Write recursive print_num_pattern () function 2 == " main ": 3 if name_ num1 = int (input ()) num2 = int(input ()) print_num_pattern (num1, num2) 4 5arrow_forward4.Rohan bought a gallon of milk with an original price of $4.25; today he gets a 15% discount before a 5% tax; display the final price of the milk.5.This function is named compound_interest, takes these arguments p r n t; compute and return a for displaya = p (1 + r/n) nt6.This function is named annuities, takes these arguments r i n; compute and return s for displays = r ((1 + i)^(n + 1))/i - rarrow_forwardComputer scientists and mathematicians often use numbering systems other than base 10. Write a program that allows a user to enter a number and a base and then prints out the digits of the number in the new base. Use a recursive function baseConversion (num, base) to print the digits. Hint: Consider base 10. To get the rightmost digit of a base 10 number, simply look at the remainder after dividing by 10. For example, 153 % 10 is 3. To get the remaining digits, you repeat the process on 15, which is just 153 // 10. This same process works for any base. The only problem is that we get the digits in reverse order (right to left). The base case for the recursion occurs when num is less than base and the output is simply num. In the general case, the function (recursively) prints the digits of num // base and then prints num % base. You should put a space between successive outputs, since bases greater than 10 will print out with multi-character "digits." For example, baseConversion(1234,…arrow_forward
- Need help Writing a function, countVowels, that accepts a string as an argument. countVowels should return the number of vowels in that string. Use recursion. example countVowels('Four score and seven years'); // => 9arrow_forwardWrite a statement that calls the recursive function backwards_alphabet() with input starting_letter. Sample output with input: 'f f e d b a 344614.2214230.qx3zgy7 1 def backwards_alphabet (curr letter): if curr_letter print(curr_letter) 2 'a': == 3 4 else: print (curr_letter) prev_letter backwards_alphabet (prev_letter) 5 chr (ord(curr_letter) 1) 7 9 starting_letter = input () 10 Your solution goes here ... 11 12arrow_forwardWrite a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, the pattern generated is as follows: **** *** ** * * ** *** **** Also, write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the preceding pattern.arrow_forward
arrow_back_ios
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