Question

In this programming assignment, you will be writing a program that prints out several shapes via text. In this PA, you will b

Program Structure In your program, you should write a function that allows you to print out these three sub-shapes. You shoul

Hi. Please help me solve this in python using only while loops, if statements. Can't use for loops and lists.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def line(n):
    #Function to draw straight lines consisting of 1 | , 9 - and 1 | in order.
    #We need to print n lines.
    while(n>0):
        print("|" + 9*"-" + "|")
        n-=1

def up_arrow(c):
    n = 1
    #Drawing up arrow, in line number i, we have 2*i - 1 characters as specified by user.
    #Remaining (11 - 2*i - 1) characters are blank spaces, distributed on each side.
    while(n<=11):
        spaces = (11-n)//2
        current_line = " "*(spaces) + n*c + " "*spaces
        print(current_line)
        n+=2

def down_arrow(c):
    n = 11
    #Drawing down arrow, in line number i, we have 13 - (2*i) characters as specified by user.
    #Remaining (2*i - 2) characters are blank spaces, distributed on each side.
    while(n>0):
        spaces = (11-n)//2
        current_line = " "*(spaces) + n*c + " "*spaces
        print(current_line)
        n-=2

def main():
    print("Enter shape to display")
    shape = input()

    print("Enter arrow character")
    arrow_character = input()

    print("Enter row area height")
    height = int(input())

    if(shape == "hourglass"):
        line(height)
        down_arrow(arrow_character)
        up_arrow(arrow_character)
        line(height)
    
    elif(shape == "plumbbob"):
        up_arrow(arrow_character)
        line(height)
        down_arrow(arrow_character)

    elif(shape == "house"):
        up_arrow(arrow_character)
        line(height)
    
    else:
        print("Please enter a valid shape")

if __name__ == "__main__":
    main()

The code has been written as per requirements. The output looks like this-

Enter shape to display hourglass Enter arrow character ! Enter row area height 3 I. - . - ! !!! !!!!!!

I would be happy to resolve any queries in the comments. Please consider dropping an upvote to help a struggling college kid :)

Happy Coding !!

Add a comment
Know the answer?
Add Answer to:
Hi. Please help me solve this in python using only while loops, if statements. Can't use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops...

    In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops for the input validations required: number of employees(cannot be less than 1) and number of days any employee missed(cannot be a negative number, 0 is valid.) Each function needs a separate flowchart. The function charts are not connected to main with flowlines. main will have the usual start and end symbols. The other three functions should indicate the parameters, if any, in start; and...

  • In python, please help me fill in these functions given their limitations. Please use for loops....

    In python, please help me fill in these functions given their limitations. Please use for loops. def palindrome(x): """ For a given string, determine if the string is a palindrome. (The same forward and back) Input: String of any size (including empty) Return: Boolean (True if palindrome, False otherwise) Limitation: You must use a loop. Only function allowed to be used is len (if needed). Cannot use "in" besides "for var in container" """ pass def getCount(char, strng): """ Get...

  • Hi I need help doing this problem *The program must re-prompt as long as invalid input...

    Hi I need help doing this problem *The program must re-prompt as long as invalid input is inserted Implement a program that manages shapes. Implement a class named Shape with a virtual function area()which returns the double value. Implement three derived classes named Diamond, Oval, and Pentagon. Declare necessary properties in each including getter and setter function and a constructor that sets the values of these properties. Override the area() function in each by calculating the area using the defined...

  • Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I...

    Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...

  • This an intro class, we can't use 'i'f statements, yet No loops, it has to be...

    This an intro class, we can't use 'i'f statements, yet No loops, it has to be very simple, something somebody with little coding experience can do. We've learned about print, and basic math function in Python Coding, this is Eiffel Tower In this program, you will print out ascii art of the eiffel tower. Name your progam eiffel tower.py. Your program should ask the user for just one number: The size of the tower. The program should support any size...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • Starting out with Python 4th edition I need help with while loops I can't even get...

    Starting out with Python 4th edition I need help with while loops I can't even get one started correctly. Write a program a program that predicts the approximate size of a population of organisms. Problem 4.13 – population Use a while loop; there are no text boxes, just regular input statements Enter number of organisms: 2 Enter average daily increase: 30 Enter number of days to multiply: 10 DAY       APPROXIMATE POPULATION ------------------------------------------------- 1            2 2            2.600 3            3.380 4            4.394...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • Using Python Write the following well-documented (commented) program. Create a class called Shape that has a...

    Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....

  • Can someone please help me with this javascript - Javascript - do at least 10 of...

    Can someone please help me with this javascript - Javascript - do at least 10 of the following questions below ----------------------------------------------------------------------------------- Create an HTML file that takes in input and carries out of the following functions and manipulates the DOM to show the outcome. Please put the question itself as a comment above each answer. Use either JavaScript, jQuery, or both (but know the difference!). ----------------------------------------------------------------------------------- 1. Fibonacci Define function: fib(n) Return the nth number in the fibonacci sequence. 2....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT