1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sdas [7]
1 year ago
12

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 nth line which shows n asterisks.
Computers and Technology
1 answer:
liraira [26]1 year ago
3 0

The follwing code represents the recursive function :

def main():

y = int(input("Please input the number of asterisks that you want to start from= "))

x = int(input("Please input the number of asterisks that you would like to draw= "))

ast(y, x)

def ast(b, a):

if b < (a + 1):

 print("*" * b)

 ast(b+1, a) # Recursive function

else:

 return 0

 

main()

Output:

Please input the number of asterisks that you want to start from= 1

Please input the number of asterisks that you would like to draw= 5

*

**

***

****

*****

Python also permits function recursion, allowing defined functions to call one another. Python allows function recursion, which lets defined functions call one another.

Recursion is a common concept in both arithmetic and programming. It indicates when a function calls itself. The benefit of this is that you can loop through the data to get a conclusion.

We are aware that a Python function has the ability to invoke another function. It's possible for a function to call itself. These kinds of constructions are referred to as recursive functions.

To learn more about recursive function click here:

brainly.com/question/26781722

#SPJ4

You might be interested in
Write a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file
timama [110]

Answer:

Here is the Python function:

import os   #module used to interact with operating system

def displayFiles(pathname):  #recursive function that takes a pathname as argument

  if (os.path.isdir(pathname)):  #checks if specified path (argument) is an existing directory

      for content in os.listdir(pathname):  #gets the list of all files and directories in the directory and iterates through the items of this list of directory

          contents = os.path.join(pathname, content)  #joins contents of path

          displayFiles(contents)  #calls function recursively

  else:  #if pathname refers to a file

      filename=pathname  #sets filename to pathname

      file = os.path.basename(filename)  #gets base name in specified path

      print("File Name: ", file) #displays the name of file

      with open(filename, "r") as contents:  #opens file in read mode

          print("Content:")  #prints Content:

          for lines in contents:  #iterates through the contents of file

              print(lines)   #displays the contents of file

Explanation:

The recursive function  displayFiles contains a single argument  pathname which can either be a pathname or a filename  . If the given argument is pathname for directory  , then the directory is opened and os.listdir returns a list containing the names of the entries in the directory given by pathname and append these contents in the list. Then this function is called recursively to print each file name and this function is applied to each name in the directory. However if the pathname refers to a file then the pathname is set to filename , the file is opened in read mode and the contents of the file are displayed.

8 0
4 years ago
Select all of the uses of presentation software in the workplace.
zaharov [31]

Answer:

uhm 1, 2, 3, 4, 6, 7, and 8.

Explanation:

because those are all the uses of presentation software in a workplace.

8 0
4 years ago
Which one of these words does not describe factual data?
defon
Opinion, because having an opinion on a topic is the same as having a bias
4 0
3 years ago
Wireshark capture files, like the DemoCapturepcap file found in this lab, have a __________ extension, which stands for packet c
grin007 [14]

Answer:

The answer is ".pcapng"

Explanation:

Wireshark format includes a "dump" with data packets, which is collected over a channel and sometimes a common folder to store, that data in the PCAP Next Iteration file system.

  • The .pcapng stands for the file system, this file system compatible with the recorded data transmission packet. It includes several data blocks.
  • It is quite robust, but it should not be helped by the other devices. Wireshark allows the libpcap system as well.
5 0
3 years ago
Which function does the Subtotal feature use?
Klio2033 [76]

max is the right answer because it give us subtotal

4 0
3 years ago
Other questions:
  • Using the drop-down menus, correctly match the name of the person with the computer-programming
    6·1 answer
  • How do you turn on the Track Changes feature in a word-processing document?
    12·1 answer
  • Can you give me a long list of kid's cartoons
    15·1 answer
  • HELP PLEASE ASAP!!! Does anyone know how to fix a broken iPhone which when I connect it to the charger it comes up with the Appl
    5·1 answer
  • how write a program to prompt the user for hours and rate per hour using input to computer gross pay Use 35 hours and rate2.75 p
    9·1 answer
  • Study the sentences below. A.Changing the properties of characters in a sentence or paragraph in a Word document helps increase
    5·2 answers
  • Convert 311 from decimal to hexadecimal. Show your work.
    9·1 answer
  • Im having trouble with PLC subject. How to make this ladder diagram?
    15·1 answer
  • If you face an investigation where dangerous substances might be around, you may need to obtain which of the following?
    13·2 answers
  • What key do I use to start my presentation
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!