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
a_sh-v [17]
3 years ago
15

Write a recursive function called DrawTriangle() that outputs lines of '*' to form a right side up isosceles triangle. Function

DrawTriangle() has one parameter, an integer representing the base length of the triangle. Assume the base length is always odd and less than 20. Output 9 spaces before the first '*' on the first line for correct formatting.
Computers and Technology
1 answer:
lorasvet [3.4K]3 years ago
4 0

Answer:

Code:-  

# function to print the pattern

def draw_triangle(n, num):

     

   # base case

   if (n == 0):

       return;

   print_space(n - 1);

   print_asterisk(num - n + 1);

   print("");

 

   # recursively calling pattern()

   pattern(n - 1, num);

   

# function to print spaces

def print_space(space):

     

   # base case

   if (space == 0):

       return;

   print(" ", end = "");

 

   # recursively calling print_space()

   print_space(space - 1);

 

# function to print asterisks

def print_asterisk(asterisk):

     

   # base case

   if(asterisk == 0):

       return;

   print("* ", end = "");

 

   # recursively calling asterisk()

   print_asterisk(asterisk - 1);

   

# Driver Code

n = 19;

draw_triangle(n, n);

Output:-  

# Driver Code n = 19;| draw_triangle(n, n);

You might be interested in
What is one potential problem with the following loop? System.out.print("Enter integers. Enter -1 to exit."); System.out.println
iris [78.8K]

Answer:

The answer to this question can be given as  

The potential problem with the loop is it's counts when the user enters -1 from the keyboard, so the count will too many.

Explanation:

In the program there some line is missing. So the right program of the  question can be given as:  

import java.util.*;     //import package for take input from user.

public class Main     //define main class.

{

public static void main(String[] args)//define main function

{

Scanner scan=new Scanner(System.in);          //creating object.

//print values.

System.out.print("Enter integers. Enter -1 to exit.");

System.out.println(" Count of integers entered will be returned.");  

 int n=0,c=0;           //declaring integer variable.

  while (n != -1)             //loop

   {

       n = scan.nextInt();               //take input by user and hold on variable n.  

       c++;

   }

 System.out.println(c);               //print value.

}

}

output:

Enter integers. Enter -1 to exit. Count of integers entered will be returned.

-1

1  

7 0
4 years ago
A computer ________ is two or more computers connected using software and hardware so that they can communicate with each other.
kolbaska11 [484]
The answer would be a network

7 0
3 years ago
Which devices are likely to include a computer? Select 3 options.
Veronika [31]

Answer:

Cell Phone, ATM Cash Machine, and a GPS Mapping Device

5 0
3 years ago
Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase
satela [25.4K]

Answer:

Read the file and save it to a variable as a string, split the string variable and cast it to a set object using the set function to get the unique words in the file. Then use the max function with the key attribute to use regular expression module "re" to compare the first letter of each item to return in a list comprehension or append to a list.

Explanation:

The open function is used to import a file in python, the split string method splits the string to a list of items and the set function removes any duplicates of a word or item.

Using the for loop statement, iterate over the items and compare and return the items in alphabetical order with the 're' search method getting the item with uppercase letters with higher precedence than lowercase.

5 0
3 years ago
Assume that scotus is a two-dimensional character array that stores the family names (last names) of the nine justices on the Su
dangina [55]

Answer:

for (int i = 0; i < 9; ++i) {

int k = 0;

while (k < 20 && scotus[i][k] != '') {

cout << scotus[i][k];

k++; }

cout << "\n"; }

Explanation:

scotus here is a two dimensional array. It contains names of 9 justices. so the loop starts from 0 and ends when i points to the last name element in the array. Then a while loop is used to check that name is longer than twenty characters and will keep on printing each output on the separate line.

Another way to write this:

for (int i = 0; i < 9; i++){

cout << scotus[i] << "\n"; }

This loop will keep on executing and printing the names of the nine justices at every iteration until it reaches the end of the array (last element of the array scotus).

5 0
3 years ago
Other questions:
  • What problem does Mitra identify in education? How can the internet and social media influence this problem?
    14·1 answer
  • On the home ribbon, what do you use to change the font size of characters in a cell
    9·1 answer
  • Syntax refers to what aspect of language? sounds of words order of words meanings of words
    12·1 answer
  • What are three distractions that can prevent a driver from focusing on driving? Explain how a driver can prevent these distracti
    15·1 answer
  • How do you make an app for help
    6·2 answers
  • A ______ workstation is a network terminal that supports a full-featured user interface, but limits the printing or copying of d
    5·1 answer
  • A network administrator was testing an IPS device by releasing multiple packets into the network. The administrator examined the
    13·2 answers
  • A discription of how child abuse displays itself on social media​
    6·1 answer
  • Iman manages a database for a website that reviews movies. If a new movie is going to be added to the database, what else will n
    7·2 answers
  • An independent penetration testing company is invited to test a company's legacy banking application developed for Android phone
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!