Question

In: Computer Science

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 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

Solutions

Expert Solution

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:

======


Related Solutions

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...
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Please write python code for the following. Implement the functions defined below. Include a triple-quoted comments...
Please write python code for the following. Implement the functions defined below. Include a triple-quoted comments string at the bottom displaying your output. Using sets (described in Deitel chapter 6) will simplify your work. Below is the starter template for the code: def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2 have in common """ return 0    def most_similar(user, interests): """ Determine the name of user who is most similar to the input user...
Please write in Python code Write a program that stores the following data in a tuple:...
Please write in Python code Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to display a menu to the user, with the following 4 options: 1 – Display minimum 2 – Display maximum 3 – Display total 4 – Display average 5 – Quit Make your program loop back to this menu until the user chooses option 5. Write code for all 4 other menu choices
Using the pseudocode found below, write only the actual (C++) code for this program. Include all...
Using the pseudocode found below, write only the actual (C++) code for this program. Include all libraries. Specification: Write a program that will repeatedly ask the user for quiz grades in the range from 0 to 20. Any negative value will act as a sentinel. When the sentinel is entered compute the average of the grades entered. Design: Constants None Variables float grade float total = 0 int count = 0 float average ------- Inital Algorithm Repeatedly ask user for...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
Write a Python program that takes information from the user about a spider seen in North...
Write a Python program that takes information from the user about a spider seen in North America and returns whether it is likely to be a dangerous spider. The only two spiders in North America that are actually dangerous are the widow and recluse. The program will ask the user for the following information: color and special markings. printWelcome – prints program information printColorMenu – Color menu options should be brown, black, other printSpecialMarkingsMenu – Special markings options should be...
write a Python program that takes information from the user about a spider seen in North...
write a Python program that takes information from the user about a spider seen in North America and returns whether it is likely to be a dangerous spider. The only two spiders in North America that are actually dangerous are the widow and recluse. The program will ask the user for the following information: color and special markings. printWelcome – prints program information printColorMenu – Color menu options should be brown, black, other printSpecialMarkingsMenu – Special markings options should be...
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT