Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 3: Arrows Write a program using python that prompts the user for a number of columns, and them prints the pattern as seen below.

Program 3: Arrows

Write a program using python that prompts the user for a number of columns, and them prints the pattern as seen below. You cannot assume that the user will supply positive numbers - if they misbehave you should re-prompt them until they do give you a positive number. Note that your program only has to run one time, but multiple runnings of the program are shown below:

How many columns? 3 * * * * *
How many columns? 5 * * * * * * * * *
How many columns? 10 * * * * * * * * * * * * * * * * * * *
How many columns? -5 Invalid entry, try again! How many columns? -2 Invalid entry, try again! How many columns? 6 * * * * * * * * * * *

Some hints:

  • Use separate while loops to make your program easier to understand. One while loop can be used for data validation (negative numbers), another can be used for one half of the arrow structure, and a third can be used for the second half. Break down your program into smaller chunks!
  • To produce the pattern shown it will be helpful to create a few accumulator variables. For example, look at the number of spaces before the star character in each line. Do you see a pattern that can be simulated using a while loop?

Next, upgrade your program so that it handles both left and right arrows. Validate your input in the same way you validate the # of columns. Here are a few sample runnings:

How many columns? 5 Direction? (l)eft or (r)ight: l * * * * * * * * *
How many columns? 5 Direction? (l)eft or (r)ight: r * * * * * * * * *
How many columns? 3 Direction? (l)eft or (r)ight: apple Invalid entry, try again! How many columns? 4 Direction? (l)eft or (r)ight: l * * * * * * *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago