In: Computer Science
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 send to it and ending with 1 star. For example, if the value sent to it is 4, the function would print this:******
•If the user enters anything other than a positive integer, your program must print an appropriate message and end.
•Your program should be tested with the following values:-5Hello018
Implemented the code as per the requirement. As python is
indentation specific, you may not get the formatted text while
copying the code,
so I'm attaching the screenshots of the code for reference. Please
make sure when you are executing the below code you have same
format, especially tabs.
Please comment if any modification required or if you need any help.
Code:
====
def goingUp(num): for i in range(1,num+1): for j in range(1,i+1): print("*",end="") print() def goingDown(num): for i in range(num-1,0,-1): for j in range(i,0,-1): print("*",end="") print() inp = input("Enter a positive number: ") if (inp.isnumeric()): if(int(inp)<=0): print("Please enter a positive number!") else: goingUp(int(inp)) goingDown(int(inp)) else: print("Invalid input!")
code screenshot:
=============
Output:
======