CS mod4

docx

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

205

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

7

Uploaded by CaptainSteelSeaUrchin27

Report
Rock-Paper-Scissors: This is a game of chance normally played between two people. Similar to flipping a coin or drawing straws, it can be used as a method for determining a random winner. The rules of the game require that each player forms one of three shapes with their hand at the same time. The shapes are as follows: Rock, which is represented by a closed fist, will beat scissors because rock can crush scissors. Paper, which is represented by a flat hand, will beat rock because paper can cover rocks. Scissors, which are represented by the index and middle fingers forming a V, will beat paper because scissors can cut through paper. In the computer version of this game, the user will play against the computer. The human user will choose rock, paper, or scissors, and the computer will also randomly choose rock, paper, or scissors. Use the integer values 1 to represent rock, 2 to represent paper , and 3 to represent scissors . The human user will input either 1, 2, or 3. The computer will then choose a random number between 1 and 3. Based on the rules of the game, the computer will give output to show whether the user or the computer wins the game, or if it is a tie. The user will play 10 games and, at the conclusion of those 10 games, the computer will output the number of times the user won, the number of times the computer won, as well as the number of tied games. To develop the program in beginners' Coral using a for loop, you can follow these steps: Step 1: Initialize the variables - Create three variables: `user_wins`, `computer_wins`, and `ties` to keep track of the number of wins and ties. - Set all three variables to 0 initially. Step 2: Import the necessary modules - Import the `random` module to generate random numbers. Step 3: Create a for loop
- Use a for loop to iterate 10 times, representing the 10 games the user will play. - In each iteration, prompt the user to input their choice (rock, paper, or scissors) and store it in a variable, let's say `user_choice`. - Generate a random number between 1 and 3 using the `random.randint()` function and store it in a variable, let's say `computer_choice`. Step 4: Determine the winner - Compare `user_choice` and `computer_choice` to determine the winner based on the rules of the game. - If `user_choice` is equal to `computer_choice`, increment the `ties` variable by 1. - If `user_choice` beats `computer_choice` according to the game rules, increment the `user_wins` variable by 1. - Otherwise, increment the `computer_wins` variable by 1. Step 5: Display the results - After the for loop, display the number of times the user won, the number of times the computer won, and the number of tied games. Here's a sample code snippet that implements the above steps: ```coral // Step 1: Initialize variables let user_wins = 0 let computer_wins = 0 let ties = 0 // Step 2: Import modules import random // Step 3: Create a for loop for i in range(10):
// Prompt user for input let user_choice = input("Enter your choice (1 for rock, 2 for paper, 3 for scissors): ") // Generate random computer choice let computer_choice = random.randint(1, 3) // Step 4: Determine the winner if user_choice == computer_choice: ties += 1 else if (user_choice == 1 && computer_choice == 3) || (user_choice == 2 && computer_choice == 1) || (user_choice == 3 && computer_choice == 2): user_wins += 1 else: computer_wins += 1 // Step 5: Display the results print("User wins:", user_wins) print("Computer wins:", computer_wins) print("Ties:", ties) ``` Note: This code assumes you are using the Coral programming language and have a basic understanding of programming concepts. Make sure to adapt the code to the specific programming language you are using if it's different from Coral.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Sure, I can help you with that. Here's a simplified flowchart for the game you described. Please note that this is a text-based representation and not a graphical one. Flowchart 1. Start 2. Initialize user score, computer score, and tie score to 0 3. For i = 1 to 10 Prompt user to enter a choice (1 for rock, 2 for paper, 3 for scissors) Generate a random number (1, 2, or 3) for the computer's choice If user choice equals computer choice Increment tie score Else If user choice is 1 (rock) and computer choice is 3 (scissors), or user choice is 2 (paper) and computer choice is 1 (rock), or user choice is 3 (scissors) and computer choice is 2 (paper) Increment user score Else Increment computer score 4. End For 5. Display user score, computer score, and tie score 6. End Table Representation Ste p Action 1 Start 2 Initialize user score, computer score, and tie score to 0 3 For i = 1 to 10 4 Prompt user to enter a choice (1 for rock, 2 for paper, 3 for scissors) 5 Generate a random number (1, 2, or 3) for the computer's choice 6 If user choice equals computer choice, increment tie score 7 Else If user choice is 1 (rock) and computer choice is 3 (scissors), or user choice is 2 (paper) and computer choice is 1 (rock), or user choice is 3 (scissors) and computer choice is 2 (paper), increment user score 8 Else, increment computer score 9 End For 10 Display user score, computer score, and tie score
Ste p Action 11 End This flowchart and table represent the basic logic of the game. You can add more details and conditions based on your specific requirements. Flowchart Description 1. Start 2. I nitialize userWins, computerWins, ties to 0 3. For i from 1 to 10 This is a loop that will repeat the following steps 10 times. 4. User inputs choice The user makes a choice. 5. Computer randomly selects choice The computer makes a random choice. 6. If userChoice equals computerChoice This is a decision point. If the user's choice is the same as the computer's choice, go to step 7. If not, go to step 8. 7. Increment ties Add one to the count of ties. Go back to step 3. 8. Else if userChoice beats computerChoice This is another decision point. If the user's choice beats the computer's choice, go to step 9. If not, go to step 10. 9. Increment userWins Add one to the count of user wins. Go back to step 3. 10. Else If none of the above conditions are met, go to step 11. 11. Increment computerWins Add one to the count of computer wins. Go back to step 3. 12. End For This is the end of the loop. If the loop has not been repeated 10 times, go back to step 3. If it has, go to step 13. 13. Display userWins, computerWins, ties
Show the final counts of user wins, computer wins, and ties. 14. End I hope this helps! If you have any other questions, feel free to ask. In the computer version of this game, the user will play against the computer. The human user will choose rock, paper, or scissors, and the computer will also randomly choose rock, paper, or scissors. Use the integer values 1 to represent rock, 2 to represent paper, and 3 to represent scissors. The human user will input either 1, 2, or 3. The computer will then choose a random number between 1 and 3. Based on the rules of the game, the computer will give output to show whether the user or the computer wins the game, or if it is a tie. The user will play 10 games and, at the conclusion of those 10 games, the computer will output the number of times the user won, the number of times the computer won, as well as the number of tied games. Determine the appropriate inputs and outputs for the situation. Determine what the game you have selected will require the user to enter as an input. Think about where the user needs to make a choice and where the computer will choose by random selection. Design branches to establish the logic of the solution. The direction should be readable and each path should have an outcome that makes sense with the logic of the solution. Design appropriate loops to establish the logic of the solution. The Cracked Egg and Rock-Paper-Scissors games will use a FOR loop since both games will run a specified number of times (12 and 10 respectively.) The Spaceship Race game will use a WHILE loop since the body of the loop will run as long as neither spaceship reaches 100. Apply correct symbols to convey the logic in the flowchart. Focus on the following symbols as you work: o Oval: Indicates the beginning step or the ending step of the flowchart
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
o Rectangle: Indicates an action or an operation in the flowchart process o Diamond: Indicates a decision point (conditional) o Parallelogram: Indicates input and output operations o Arrows: Indicate directional flow of the logic