Forum Archive

Chartz

reefboy1

This one is dedicated to ccc (I watched the EuroPython!) for all his
Help due to me being new and somewhat unsmart mistakes
This is my app that makes a chart
And is called Chartz



# PieMaker
# This simple thingymajigger (<- be careful that word is in no way professional)
# allows you to enter three % numbers and will make a bar chart.
print('Enter three percentage numbers that add up to 100%...\n')

a = raw_input('Enter % ') or '20'  # 20 is the default value if user just presses enter
aPIE = int(a)
b = raw_input('Enter % ') or '30'
bPIE = int(b)
c = raw_input('Enter % ') or '50'
cPIE = int(c)
total = aPIE + bPIE + cPIE  # make sure the three numbers add up to 100%
assert total == 100, '{} + {} + {} = {} != 100!'.format(a, b, c, total)

n1 = raw_input('Name your first bar ({}%): '.format(a))  or 'first'
n2 = raw_input('Name your second bar ({}%): '.format(b)) or 'second'
n3 = raw_input('Name your third bar ({}%): '.format(c))  or 'third'
print('')

dividing_line = '| {} |'.format('-' * 36)
fmt = '| {:>10} {:>3}% {:<20} |'
print(dividing_line)
stars  = '*' * (aPIE / 5)  # one star for every 5%
print(fmt.format(n1, a, stars))
print(dividing_line)
stars  = '*' * (bPIE / 5)
print(fmt.format(n2, b, stars))
print(dividing_line)
stars  = '*' * (cPIE / 5)
print(fmt.format(n3, c, stars))
print(dividing_line)

ccc

Thanks for the dedication! It is more of a bar chart than a pie chart. A few ideas...

# PieMaker
# This simple thingymajigger (<- be careful that word is in no way professional)
# allows you to enter three % numbers and will make a bar chart.
print('Enter three percentage numbers that add up to 100%...\n')

a = raw_input('Enter % ') or '20'  # 20 is the default value if user just presses enter
aPIE = int(a)
b = raw_input('Enter % ') or '30'
bPIE = int(b)
c = raw_input('Enter % ') or '50'
cPIE = int(c)
total = aPIE + bPIE + cPIE  # make sure the three numbers add up to 100%
assert total == 100, '{} + {} + {} = {} != 100!'.format(a, b, c, total)

n1 = raw_input('Name your first pie ({}%): '.format(a))  or 'first'
n2 = raw_input('Name your second pie ({}%): '.format(b)) or 'second'
n3 = raw_input('Name your third pie ({}%): '.format(c))  or 'third'

dividing_line = '| {} |'.format('-' * 36)
fmt = '| {:>10} {:>3}% {:<20} |'
print('\n' + dividing_line)
stars  = '*' * (aPIE / 5)  # one star for every 5%
print(fmt.format(n1, a, stars))
print(dividing_line)
stars  = '*' * (bPIE / 5)
print(fmt.format(n2, b, stars))
print(dividing_line)
stars  = '*' * (cPIE / 5)
print(fmt.format(n3, c, stars))
print(dividing_line)

Output should look like this:

Enter three percentage numbers that add up to 100%...

Enter % 50
Enter % 30
Enter % 20
Name your first pie (50%): won
Name your second pie (30%): lost
Name your third pie (20%): tied

| ------------------------------------ |
|        won  50% **********           |
| ------------------------------------ |
|       lost  30% ******               |
| ------------------------------------ |
|       tied  20% ****                 |
| ------------------------------------ |
reefboy1

Oh! Sorry I'm only in elementary school xD! I got confused. Thanks for the help! Mind if I use this?

ccc

Go ahead and use it. ;-)