Advertisement
1zenky

Untitled

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