lamiastella

tickets

Jun 22nd, 2016
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # https://www.codewars.com/kata/555615a77ebc7c2c8a0000b8/train/python
  2. '''
  3. The new "Avengers" movie has just been released! There are a lot of people at the cinema
  4. box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill.
  5. A "Avengers" ticket costs 25 dollars. Vasya is currently working as a clerk. He wants to
  6. sell a ticket to every single person in this line. Can Vasya sell a ticket to each person
  7. and give the change if he initially has no money and sells the tickets strictly in the
  8. order people follow in the line? Return YES, if Vasya can sell a ticket to each person
  9. and give the change. Otherwise return NO.
  10. Examples:
  11. ### Python ###
  12. tickets([25, 25, 50]) # => YES
  13. tickets([25, 100])
  14.         # => NO. Vasya will not have enough money to give change to 100 dollars
  15. '''
  16.  
  17. def tickets(people):
  18.     sum = 0
  19.     for p in people:
  20.         if p < 25:
  21.             return 'NO'
  22.         if p == 25:
  23.             sum += p
  24.         elif p > 25:
  25.             if (sum - p) <0 :
  26.                 return 'NO'
  27.             else:
  28.                 sum += p
  29.     return 'YES'
Advertisement
Add Comment
Please, Sign In to add comment