thumbWar.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2020, 2019 Girish M
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  15. # MA 02110-1301, USA.
  16. #
  17. import random
  18. choice = 'y'
  19. player_score = 0
  20. comp_score = 0
  21. while choice in ['y', 'Y', 'Yes']:
  22. p = random.choice([1,2,3,4,5,6,7,8,9,10])
  23. print(p, '- player')
  24. c = random.choice([1,2,3,4,5,6,7,8,9,10])
  25. print(c, '- computer')
  26. if p > c:
  27. print ("player wins! ")
  28. player_score += 1
  29. elif p < c:
  30. print("computer wins!")
  31. comp_score += 1
  32. else:
  33. print ("It's a tie! no one gets a point.")
  34. print("Your score so far is: ", player_score)
  35. print("Computer's score so far is: ", comp_score)
  36. choice = input("Would you like to play again('y' or 'n')?: ")
  37. print("Your score is: ", player_score)
  38. print("Computer score is: ", comp_score)