Guest User

Untitled

a guest
Apr 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. from pylab import show, plot, ylabel, xlabel, barh, yticks, title, grid
  2. import sys
  3. import time
  4. always_true = 1
  5. labels = []
  6. total_expenses = []
  7. while always_true == 1:
  8. try:
  9. categories = int(input('How many categories would you like on your expenditures chart? '))
  10. except ValueError:
  11. print ('Invalid input.')
  12. time.sleep(3)
  13. sys.exit()
  14. if categories > 0:
  15. print ('No problem!')
  16. break
  17. else:
  18. print ('Invalid input.')
  19. while categories > 0:
  20. category_name = input('Enter a categoty: ')
  21. try:
  22. expenses = int(input('Enter your expenses: '))
  23. except ValueError:
  24. print ('Invalid input.')
  25. sys.exit()
  26. if expenses > 0:
  27. print ('OK!')
  28. else:
  29. print ('Invalid input.')
  30. labels.append(category_name)
  31. total_expenses.append(expenses)
  32. categories -= 1
  33. num_bars = len(total_expenses)
  34. positions = range(1, num_bars + 1)
  35. barh(positions, total_expenses, align = 'center')
  36. yticks(positions, labels)
  37. ylabel('Category')
  38. xlabel('Money spent')
  39. title('Expenditures chart')
  40. grid()
  41. show()
Add Comment
Please, Sign In to add comment