Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Simple version of rock paper and scissors."""
- import random
- def normalize_user_name(name: str) -> str:
- """
- Simple function gets player name as input and capitalizes it.
- :param name: name of the player
- :return: A name that is capitalized.
- """
- user_name = input("What is your name? ")
- normalize_user_name(user_name)
- def reverse_user_name(name: str) -> str:
- """
- Function that takes in name as a parameter and reverses its letters. The name should also be capitalized.
- :param name: name of the player
- :return: A name that is reversed.
- """
- if reverse_user_name:
- reverse_user_name(normalize_user_name(user_name))
- def check_user_choice(choice: str) -> str:
- """
- Function that checks user's choice.
- The choice can be uppercase or lowercase string, but the choice must be
- either rock, paper or scissors. If it is, then return a choice that is lowercase.
- Otherwise return 'Sorry, you entered unknown command.'
- :param choice: user choice
- :return: choice or an error message
- """
- user_choice = input("What is your choice? ")
- if user_choice == "rock" or "paper" or "scissors":
- True
- else:
- print("There is a problem determining the winner.")
- check_user_choice(user_choice)
- user_choice.lower()
- computer_choice = random.choice
- if user_choice == "rock" and computer_choice == "rock":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence it is a draw.")
- if user_choice == "rock" and computer_choice == "paper":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence {winner} wins.")
- if user_choice == "rock" and computer_choice == "scissors":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence {winner} wins.")
- if user_choice == "paper" and computer_choice == "paper":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence it is a draw.")
- if user_choice == "paper" and computer_choice == "rock":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence {winner} wins.")
- if user_choice == "paper" and computer_choice == "scissors":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence {winner} wins.")
- if user_choice == "scissors" and computer_choice == "rock":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence {winner} wins.")
- if user_choice == "scissors" and computer_choice == "paper":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence {winner} wins.")
- if user_choice == "scissors" and computer_choice == "scissors":
- print("{user_name} had {user_choice} and computer had {computer_choice}, hence it is a draw.")
- def determine_winner(name: str, user_choice: str, computer_choice: str, reverse_name: bool = False) -> str:
- """
- Determine the winner returns a string that has information about who won.
- You should use the functions that you wrote before. You should use check_user_choice function
- to validate the user choice and use normalize_user_name for representing a correct name. If the
- function parameter reverse is true, then you should also reverse the player name.
- NB! Use the previous functions that you have written!
- :param name:player name
- :param user_choice:
- :param computer_choice:
- :param reverse_name:
- :return:
- """
- print(determine_winner(user_name, user_choice, computer_choice))
- play_more = True if input("Do you want to play more ? [Y/N] ").lower() == 'y' else False
- def play_game() -> None:
- """
- Enables you to play the game you just created.
- :return:
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement