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

Write a Ruby script that allows a human player to play the Rock-Paper-Scissors g

ID: 648901 • Letter: W

Question

Write a Ruby script that allows a human player to play the Rock-Paper-Scissors game against the computer.  

To play the game, the human player chooses one of "rock," "paper," or "scissors." The computer also chooses, randomly with equal probability, one of these three plays.

These phases determine the winner for each combination: "rock crushes scissors", "scissors cuts paper," and "paper covers rock."

In this diagram, each arrow points from the winner to the user.

If both the human and the computer choose the same play, there is a tie.

Here is a sample script output. The human player's choices are shown in red.

You can base your script on this pseudocode:

Also show the answer!!

Write a Ruby script that allows a human player to play the Rock-Paper-Scissors game against the computer. To play the game, the human player chooses one of rock, paper, or scissors. The computer also chooses, randomly with equal probability, one of these three plays. These phases determine the winner for each combination: rock crushes scissors, scissors cuts paper, and paper covers rock. In this diagram, each arrow points from the winner to the user. If both the human and the computer choose the same play, there is a tie. Here is a sample script output. The human player's choices are shown in red.

Explanation / Answer

Choices = %w(rock paper scissors) puts 'Rock, paper or scissors' draws = wins = losses = 0 10.times do begin puts "-----------------please enter rock paper or scissors-----------------" human_choice = gets.chomp.downcase end until Choices.include?(human_choice) computer_choice_idx = rand(3) puts "You chose #{human_choice}, computer choose #{Choices[computer_choice_idx]}" if human_choice == Choices[computer_choice_idx] puts "---->draw" draws += 1 elsif human_choice == Choices[computer_choice_idx - 1] puts "---->Computer wins" losses += 1 else puts "---->You win" wins += 1 end end puts "wins : #{wins} losses : #{losses} draw: #{draws}" if wins > losses puts "You won the game" elsif wins
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote