Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A rock, paper, scissors program in python This is given: # coding: utf-8 # # hw0pr2a.py # import random # imports the library named random
A rock, paper, scissors program in python
This is given:
# coding: utf-8 # # hw0pr2a.py # import random # imports the library named random def rps(): """This plays a game of rock-paper-scissors (or a variant of that game) Arguments: none (prompted text doesn't count as an argument) Results: none (printing doesn't count as a result) """ user = input("Choose your weapon: ") comp = random.choice(['rock', 'paper', 'scissors']) print() print('The user (you) chose', user) print('The computer (I) chose', comp) print() if user == 'rock': print('Ha! I really chose paper--I WIN!') print("Better luck next time...")
This is needed:
- The basic requirements are these: use the discussion from class and hw0pr2a.py's starter code (below) to create a program that:
- Invites the user to play a game of "rock-paper-scissors."
- Lets the user choose from at least three options
- They don't have to be rock, paper, and scissorsfeel free to vary the actors!
- But your program does have to work differently for each of three distinct inputs (well, at least three inputs)
- Your program is welcome to play an honest game of RPS
- But you're also welcome to create a player that always wins (or, if you prefer, that always loses)
- Your program should echo the choice the user made
- You may assume the user will type her/his choice correctly, however your game defines "correctly"
- Your program should reveal the choice that it makes (whether fair or not)
- Your program should print out who won that round (or whether it was a tie, or some other outcome)
- Side comments for the graders who will be running your program are optionalbut strongly encouraged!
More details
- In brief, the program should ask the user to choose rock, paper, or scissors (or your own variants!). Then it should repeat that choice back to the user, reveal its own choice, and finally report the results. The program can play fairly, can always win, or can always loseit's up to you. If RPS is unfamiliar, in the game of rock-paper-scissors, rock defeats scissors, scissors defeat paper, and paper defeats rock.
- You may assume that the user will input one of rock, paper, or scissors. Case matters! We'll stick with lower case...
- You may write the dialog however you likebelow is an example dialog if you'd like one to follow. We are positive that you can improve on this interaction, however! Here are two distinct runs of another program:
In [1]: run hw0pr2a.py In [2]: rps() Choose your weapon: rock The user (you) chose rock The computer (I) chose scissors Ha! I really chose paper--I WIN! Better luck next time... In [3]: rps() Choose your weapon: paper the user (you) chose paper the computer (I) chose dynamite Dynamite!? I REALLY WIN! You can't play again.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started