Uploaded by Nguyen Thi Da Ly

while-problem

advertisement

UG 2061

ASCII Bar Chart

Nov. 20

Write a function named draw bar chart that prompts the user for the height of bars that will be displayed in a bar chart, and then draws the appropriate bar chart pattern as shown below.

Notes and Constraints

• The user may enter as many bar heights as they want. You are guaranteed that the bar heights will be non-negative integers. Entering a negative number signifies that the user is done entering data.

• Save the bar heights as you read them in a list. You will want to use the .append() method to add items to your list.

• Each bar should be drawn with the appropriate number of #-symbols as shown below.

Examples

Here are some examples of how your code is expected to behave. Text in red represents user input.

1.

How tall is your bar?

5

How tall is your next bar?

3

How tall is your next bar?

1

How tall is your next bar?

-1

5 # # # # #

3 # # #

1 #

2.

How tall is your bar?

2

How tall is your next bar?

5

How tall is your next bar?

0

How tall is your next bar?

7

How tall is your next bar?

-1

2 # #

5 # # # # #

0

7 # # # # # # #

Download