Question

In: Computer Science

Write a python code which prints triangle of stars using a loop ( for loop )...

Write a python code which prints triangle of stars using a loop ( for loop ) Remember what 5 * "*" does

The number of lines of output should be determined by the user. For example, if the user enters 3, your output should be:

*

**

***

If the user enters 6, the output should be:

*

**

***

****

*****

******

You do NOT need to check for valid input in this program. You may assume the user enters a positive integer.

Solutions

Expert Solution

n=int(input("Enter number of lines:- "))
for i in range(1, n+1):
for j in range(1, i+1):
print("*", end="")
print()

Code snippet for your help in indentation

n=int(input("Enter number of lines:- "))
for i in range(1, n+1):
    for j in range(1, i+1):
        print("*", end="")
    print()

Output:-

Enter number of lines:- 6                                                                             

*                                                                                                     

**                                                                                                    

***                                                                                                   

****                                                                                                  

*****                                                                                                 

******  

Enter number of lines:- 6                                                                             
*                                                                                                     
**                                                                                                    
***                                                                                                   
****                                                                                                  
*****                                                                                                 
******  

For any query in any part of the answer you can comment below.

If you like the answer please give a like.

Happy to help. :)


Related Solutions

Complete the following in syntactically correct Python code. Write a program, using a for loop, that...
Complete the following in syntactically correct Python code. Write a program, using a for loop, that calculates the amount of money a person would earn over a period of time if his or her salary is 1 penny for the first day, 2 pennies for the second day, 4 pennies for the third day, and continues to double each day. 1.      The program should ask the user for the number of days the employee worked. 2.      Display a table showing the salary...
python code You are to write a program which produces a triangle as seen below. •Include...
python code You are to write a program which produces a triangle as seen below. •Include a function named goingUpwhich accepts a value and prints lines of stars beginning at 1 star and ending at the number of stars which was sent to it. For example, if the value sent to it is 4, the function would print this:********** •Include a function named goingDown which accepts a value and prints lines of stars beginning at 1 LESS THAN the value...
Important: please use python. Using while loop, write python code to print the times table (from...
Important: please use python. Using while loop, write python code to print the times table (from 0 to 20, incremented by 2) for number 5. Add asterisks (****) so the output looks exactly as shown below.   Please send the code and the output of the program. ****************************************************************** This Program Shows Times Table for Number 5 (from 0 to 20) Incremented by 2 * ****************************************************************** 0 x 5 = 0 2 x 5 = 10 4 x 5 = 20 6...
Write a Python loop that goes through the list and prints each string where the string...
Write a Python loop that goes through the list and prints each string where the string length is three or more and the first and last characters of the strings are the same. Test your code on the following three versions of the list examples: examples = ['abab', 'xyz', 'aa', 'x', 'bcb'] examples = ['', 'x', 'xy', 'xyx', 'xx'] examples = ['aaa', 'be', 'abc', 'hello'].
Code in python Write a while loop code where it always starts form 2. Then it...
Code in python Write a while loop code where it always starts form 2. Then it randomly chooses a number from 1-4. If the number 4 is hit then it will write “TP” if the number 1 is hit then it will write”SL”. It will rerun the program every time the numbers 1 and 5 are hit. The code should also output every single number that is randomly chosen. 2 of the same numbers can't be chosen back to back...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which are less than 100. Your loop initially starts from 0. 2. Consider B to be a list of alphabetically ordered strings. Using while loops, write a program that only prints words which start with letter A. B = [Alex, Airplane, Alpha, Australia, Ben, Book, Bank, Circuit, Count, Dark] 3. Using while loop, create a program that only prints first 18 multiples of 7.Hint: Your...
Create a python code that calculates fixed point iteration method using a for loop.
Create a python code that calculates fixed point iteration method using a for loop.
In python write a program which prints the longest substring of numbers which occur in ascending...
In python write a program which prints the longest substring of numbers which occur in ascending order s=342153476757561235
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Write a C++ code using while loop which is getting the two integers from the user,...
Write a C++ code using while loop which is getting the two integers from the user, and output how many numbers are multiples of 5, and how many numbers are multiples of 7 between the two integers (inclusive).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT