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

PUT IN PYTHON LANGUAGE CODE # Write one while-loop that starts at 500 and prints every...
PUT IN PYTHON LANGUAGE CODE # Write one while-loop that starts at 500 and prints every 6th number down to 300 # (i.e., prints 500, 494, 488, . . . etc., but does not print any number lower than 300). # Write one while-loop that starts at 80 and prints every 12h number thereafter, # but does not print any number greater than 210 # Write one while-loop that prints all the numbers from 30 through 70, # except for...
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...
Create Python Code using a "for" loop and a "while" loop. You are starting a twelve...
Create Python Code using a "for" loop and a "while" loop. You are starting a twelve week program training to compete in a triathlon. The triathlon consists of three athletic events, 1.5 k swim, 40k bike, 10k run. In order to be prepared for the competition you want to print a training schedule. Starting with week 1 you will increase the distance of each activity so that you reach the race distance by week twelve. Due to rounding, you may...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT