Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pylab import show, plot, ylabel, xlabel, barh, yticks, title, grid
- import sys
- import time
- always_true = 1
- labels = []
- total_expenses = []
- while always_true == 1:
- try:
- categories = int(input('How many categories would you like on your expenditures chart? '))
- except ValueError:
- print ('Invalid input.')
- time.sleep(3)
- sys.exit()
- if categories > 0:
- print ('No problem!')
- break
- else:
- print ('Invalid input.')
- while categories > 0:
- category_name = input('Enter a categoty: ')
- try:
- expenses = int(input('Enter your expenses: '))
- except ValueError:
- print ('Invalid input.')
- sys.exit()
- if expenses > 0:
- print ('OK!')
- else:
- print ('Invalid input.')
- labels.append(category_name)
- total_expenses.append(expenses)
- categories -= 1
- num_bars = len(total_expenses)
- positions = range(1, num_bars + 1)
- barh(positions, total_expenses, align = 'center')
- yticks(positions, labels)
- ylabel('Category')
- xlabel('Money spent')
- title('Expenditures chart')
- grid()
- show()
Add Comment
Please, Sign In to add comment