Answered step by step
Verified Expert Solution
Link Copied!

Question

...
1 Approved Answer

Convert given python code to Java Code def RSP(): guess = while (True): guess = input(Enter (r)ock, (s) cissors, or (p)aper: ) if (guess

Convert given python code to Java Code


def RSP(): guess =  

def RSP(): guess = "" while (True): guess = input("Enter (r)ock, (s) cissors, or (p)aper: ") if (guess not in ["r", "s", "p"]): print("Only 'r', 's', or 'p' are valid inputs! Please try again.") else: break rand = random() if (rand < 1/3): comp = "r" elif (rand < 2/3): comp= "s" else: comp = "p" if (guess == comp): print("It is a tie!") elif ((guess == 'r') and (comp=== 'p')) or \ ((guess == 'p') and (comp== 's')) or \ ((guess 's') and (comp == 'r')): print("Sorry, you lost as I had", comp) print("Congrats, you won as I had", comp) RSP() else: --

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Data Structures and Algorithms in Python

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

1st edition

978-1118290279

More Books

Students also viewed these Programming questions

Question

Graph the function f ( x ) = | 3 x + 9 |

Answered: 1 week ago

Question

6-4 Explain how to use two work simulations for selection.

Answered: 1 week ago

Question

5-21. What would a Hotel Paris help wanted ad look like?

Answered: 1 week ago