Question: # 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

# 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)))

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!