Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago