1: Rock, Paper, Scissors (Topics: Variables, user-input, flow-control, function) [20pnts] Task 1 implements the "rock, paper, scissors" game. This is a two-player game, where
each player simultaneously selects from one of three options: rock, paper, scissors.
The game is typically played with hand gestures and has the following rules:
Rock wins against scissors, loses to paper, ties with rock. Paper wins against rock, loses to scissors, ties with paper. Scissors win against rock, lose to paper, tie with scissors.
Image credit: Enzoklop (CC) In our version, the user will select first, and then the computer opponent named "HAL" will make a random selection.
In a real game, both players would make their selection simultaneously.
In addition to the task1() function, you need to implement the following function: printOutcome(params: userSelection, computerSelection) -> no return
The parameters are the user's and computer's selection. The function prints the outcomes depending on the selections: (1) "You win!"; (2) "HAL wins!"; (3) "A tie!"
You decide what data type the parameters should be (e.g., integers representing the selection or strings representing "rock", "paper", "scissors"). Just ensure your function prints the correct outcome.
Task 1 should behave as follows:
(1) Print "Rock, Paper, Scissors!"
(2) Print "Make your selection. . ."
(3) Get input from user – 1 (rock), 2 (paper), 3 (scissors).
(4) If the input is not 1, 2, or 3, print "Invalid selection. Try again." and ask the user for input again.
(5) Randomly select HAL's choice – rock, paper, scissors.
(6) Print out the user's selection and HAL's selection.
(7) Pass the user's and HAL's selections to the function printOutcome() to print the outcome of the game. (8) Ask the user if they want to play again (Y). If the input is 'Y' or 'y', go back to (2).
Task 2 – Adjacent element swap for a list (Topics: list, loops, functions, string manipulation, assert) [20pnts] The user will input a string as a series of characters separated by spaces. The input string should be converted to a list of characters. Task 2 is to swap the values of every two items in the list; for example – items at positions 0 and 1 are swapped; items 2 and 3 are swapped; items 4 and 5 are swapped, and so on, until the end of the list. You can assume that the list has at least two items – if not, your swap function should raise an AssertionError (see details below).
Note that there are two cases: (1) the list has an even number of elements; (2) the list has an odd number of elements. For case 1, swap all elements. For case 2, swap all elements but leave the last element unchanged.
See the diagram below for examples.
In addition to the task2() function, you need to implement the following function: swapAdjacentElements(params: alist) -> no return
The parameter alist is a list of characters. The function should modify the list as described above. should modify the list passed to the function and not create a new list. The function has no return. ASSERT: This function should assert with the following error if the list has less than two (2) characters:
"Must enter two or more characters!"
Task 2 should behave as follows:
(1) Prompt the user to input a sequence of two or more characters separated by spaces. (2) Convert the input string into a list of characters.
(3) Print the list.
(4) Print the list as a string with no spaces between the characters.
(5) Call function swapAdjacentElements() to modify the list.
See instructions above. This function does not create a new list; instead, it should modify the list passed as an argument.
(6) Print the list again to show that the list has been modified.
(7) Print the list as a string again with no spaces between the characters
Hi, I have read all the requirements and I can complete this activity in just 1 day if given the opportunity. I have 3 + years of experience in python development and I would love to work on this.
24 freelancere byder i gennemsnit $22/timen for dette job
Hi there, I do Python programming. I went through your requirements and I would like to do this project if given the opportunity. Let me know if you are interested.
Hello, dear! I have a deep experience with python. I have mastered algorithms and data structure. I can solve your problem very fast. Please contact me. Respectfully yours.