Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. """Simple version of rock paper and scissors."""
  2. from random import choice
  3.  
  4. def normalize_user_name(name: str) -> str:
  5. """
  6. Simple function gets player name as input and capitalizes it.
  7.  
  8. :param name: name of the player
  9. :return: A name that is capitalized.
  10. """
  11. pass
  12.  
  13.  
  14. def reverse_user_name(name: str) -> str:
  15. """
  16. Function that takes in name as a parameter and reverses its letters. The name should also be capitalized.
  17.  
  18. :param name: name of the player
  19. :return: A name that is reversed.
  20. """
  21. pass
  22.  
  23.  
  24. def check_user_choice(choice: str) -> str:
  25. """
  26. Function that checks user's choice.
  27.  
  28. The choice can be uppercase or lowercase string, but the choice must be
  29. either rock, paper or scissors. If it is, then return a choice that is lowercase.
  30. Otherwise return 'Sorry, you entered unknown command.'
  31. :param choice: user choice
  32. :return: choice or an error message
  33. """
  34. pass
  35.  
  36.  
  37. def determine_winner(name: str, user_choice: str, computer_choice: str, reverse_name: bool = False) -> str:
  38. """
  39. Determine the winner returns a string that has information about who won.
  40.  
  41. You should use the functions that you wrote before. You should use check_user_choice function
  42. to validate the user choice and use normalize_user_name for representing a correct name. If the
  43. function parameter reverse is true, then you should also reverse the player name.
  44. NB! Use the previous functions that you have written!
  45.  
  46. :param name:player name
  47. :param user_choice:
  48. :param computer_choice:
  49. :param reverse_name:
  50. :return:
  51. """
  52. pass
  53.  
  54.  
  55. def play_game() -> None:
  56. """
  57. Enables you to play the game you just created.
  58. :return:
  59. """
  60. user_name = input("What is your name? ")
  61. play_more = True
  62. while play_more:
  63. computer_choice = choice(['rock', 'paper', 'scissors'])
  64. user_choice = check_user_choice(input("What is your choice? "))
  65. print(determine_winner(user_name, user_choice, computer_choice))
  66. play_more = True if input("Do you want to play more ? [Y/N] ").lower() == 'y' else False
  67.  
  68.  
  69. if __name__ == "__main__":
  70. print(normalize_user_name('ago')) # Ago
  71. print(normalize_user_name('AGO')) # Ago
  72. print(normalize_user_name('MaRtInA')) # Martina
  73.  
  74. print(reverse_user_name('MaRtInA')) # Anitram
  75. print(reverse_user_name('AGO')) # Oga
  76.  
  77. print(check_user_choice('rock')) # rock
  78. print(check_user_choice('ROCK')) # rock
  79. print(check_user_choice('midagi on viltu')) # Sorry, you entered unknown command.
  80.  
  81. # 50% on juba tehtud, tubli töö!
  82.  
  83. print(determine_winner('ago', 'rock', 'paper')) # Ago had rock and computer had paper, hence computer wins.
  84. print(determine_winner('ago', 'rock', 'paper', True)) # Oga had rock and computer had paper, hence computer wins.
  85. print(
  86. determine_winner('loORa', 'SCISSORS', 'paper')) # Loora had scissors and computer had paper, hence Loora wins.
  87. print(determine_winner('Shakira', 'waka waka', 'fire')) # There is a problem determining the winner.
  88. print(determine_winner('Shakira', 'rock',
  89. 'sciSSOrs')) # Shakira had rock and computer had scissors, hence Shakira wins.
  90.  
  91. # play_game() # Kommenteeri see rida välja kui kõik funktsioonid on valmis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement