Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(((THIS NEEDS TO BE SOLVED BY R STUDIO))) # Rock Paper Scissors! # Part 1. Write

ID: 3785139 • Letter: #

Question

(((THIS NEEDS TO BE SOLVED BY R STUDIO)))

# Rock Paper Scissors! # Part 1. Write a function that takes as inputs the choice of Rock, Paper, or Scissors for player_1 and player_2 # and returns the correct winner. The function should return the values "Player 1", "Player 2", or "Tie" appropriately rock_paper_scissors <- function(player_1, player_2){ # use the if else if else structure we discussed in class if () { winner <- return(winner) } else if () { winner <- return(winner) } else { winner <- return(winner) } } # test the results rock_paper_scissors("rock","rock") == "Tie" rock_paper_scissors("rock","paper") == "Player 1" rock_paper_scissors("scissors","rock") == "Player 2" # Part 2. Write a function that takes as inputs the choice of Rock, Paper, or Scissors for user and then uses the function sample() # to randomly assign the computer to be "rock","paper", or "scissors". The function should return either # "Computer", "User", or "Tie" depending on the winner. It should also print either "The winner is computer" or "The winner is user" # or "Tie" rock_paper_scissors_computer <- function(user){ options <- c("rock","paper","scissors") computer <- print(paste("computer is", computer)) if () { winner <- return(winner) } else if () { winner <- return(winner) } else { winner <- return(winner) } } # Part 3. Write a for loop that loops over all the inputs in the vector inputs and plays rock_paper_scissors_computor. # Use a counter variable to keep track of the number of times you beat the computer inputs <- c("rock","paper","rock","scissors","paper","paper") wins <- 0 for () { if(){ wins <- }

(((THIS NEEDS TO BE SOLVED BY R STUDIO)))

}

Explanation / Answer

1.

# Rock , Paper , or Scissors Program
rock_paper_scissors <- function(player_1, player_2){
if(player_1==player_2){
winner <- "Tie"
return(winner)}
else if(player_1=="rock"&&(player_2=="paper"||player_2=="scissors")){
winner <- "Player 1"
return(winner)}
else if(player_1=="paper"&&player_2=="scissors"){
winner <- "Player 1"
return(winner)}
else if(player_2=="rock"&&(player_1=="paper"||player_1=="scissors")){
winner <- "Player 2"
return(winner)}
else if(player_2=="paper"&&player_1=="scissors"){
winner <- "Player 2"
return(winner)}
}
rock_paper_scissors("paper","scissors")