Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me out with this code. It is written through Code HS in python language. Below I have the instructions and at the bottom,

Please help me out with this code. It is written through Code HS in python language. Below I have the instructions and at the bottom, I will have the functions that were from part 2 (the part in the main function is also from part 2, I left it in case it was needed for something.)

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

I am going to attach the flowchart as well.

image text in transcribed

Computer Programming Nimgrab Strategy Game, Part 3 In this lab, we will make a strategy game called Nimgrab. You and the computer take turns taking a number or numbers away from the end of a list (17-23 numbers to begin). There is a limit to how many you can take away each move. This limit is assigned randomly at the beginning of the game (3 or 4). The winner is the player who forces the other player to take the last number Test the program with maxCanGrab = 4 and numbersLeft = 17. When you have passed all tests, change the Part number in the comments at the top of the code to 4, COMMENT the code rather than deleting it, and you can work on these extra features: Make the maxCan Grab randomly 3 or 4 Make the board printed a random odd number from 17-23 Make the computer's choice a smart choice so it is harder to win for the player. If you do this, please comment you new code, and uncooment your new code. Also, change the Part number back to 3. . Required Python elements: Variables used for inputs, outputs and other values needed for computations. Proper naming of the variables Using the input function to get the data Proper use of mathematical operators Concatenation of string and integer types Proper use of if statements, while and for loops, and functions. Include the following functions you create in Part 2 DO NOT USE THE INFINITE LOOP ( while true: ) AND break. Use the flowchart to layout your code. Rememember to start with the big ideas and inner loops first. Use the functions from part 2 when needed, do not recreate the code from these functions. Example Ouput Here is an example output of the game link to video: The maximum you can grab is 4 - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 - How many will you grab? 3 You took 3, I took 2 The maximum you can grab is 4 - 1 2 3 4 5 6 7 8 9 10 11 12 - How many will you grab? 3 You took 3, I took 3 The maximum you can grab is 4 - 1 2 3 4 5 6 - How many will you grab? 2 You took 2, I took 1 The maximum you can grab is 4 - 1 2 3 - How many will you grab? 2 The player won Do you wany to play again (Yes/No)? n Final Record: You won 1 game. I won games. Thanks for playing! import random random.seed (1) # Name: # Date: 278/21 # Class: 3 # Project: Nimgrab Strategy Game # Part: 3 Functions def getPlayerChoice(): number = int(input("How many will your grab? ")) while (number 4) or (number > 17): print ("Invalid Value") number = int(input("How many will your grab? ")) return number def getCompChoice(): smart_choice = random.randint(1, maxCanGrab) return smart_choice def printBoard(number): print "-", for i in range (1, number+1): print i, print ("-") def printFinalRecord (number, number2): print ("Final Record: ") print ("You won " + str(number) + print ("I won " + str(number2) + games") games") # ======= Main Program maxCanGrab numbers Left 4 17 # The maximum number of values that can be grabbbe # The number of values left on the board print ("You took " + str(getPlayerChoice())) print ("I took + str(getCompchoice())) printBoard(numbersLeft) printFinalRecord(5,0) || Start Create List of Numbers (Initialize the variables: max number to grab, number of values on the board) True While there are grater than 0 numbers left? Play again? True Display the numbers on the board Display how many games the player and computer won Get the player's number to grab FINISH Subtract the player's choice from the board True Display the play won Are there are grater than 0 numbers left? False Get the computer's number to grab Subtract the computer's choice from the board True Display computer won Are there are grater than 0 numbers left False Display the choices Computer Programming Nimgrab Strategy Game, Part 3 In this lab, we will make a strategy game called Nimgrab. You and the computer take turns taking a number or numbers away from the end of a list (17-23 numbers to begin). There is a limit to how many you can take away each move. This limit is assigned randomly at the beginning of the game (3 or 4). The winner is the player who forces the other player to take the last number Test the program with maxCanGrab = 4 and numbersLeft = 17. When you have passed all tests, change the Part number in the comments at the top of the code to 4, COMMENT the code rather than deleting it, and you can work on these extra features: Make the maxCan Grab randomly 3 or 4 Make the board printed a random odd number from 17-23 Make the computer's choice a smart choice so it is harder to win for the player. If you do this, please comment you new code, and uncooment your new code. Also, change the Part number back to 3. . Required Python elements: Variables used for inputs, outputs and other values needed for computations. Proper naming of the variables Using the input function to get the data Proper use of mathematical operators Concatenation of string and integer types Proper use of if statements, while and for loops, and functions. Include the following functions you create in Part 2 DO NOT USE THE INFINITE LOOP ( while true: ) AND break. Use the flowchart to layout your code. Rememember to start with the big ideas and inner loops first. Use the functions from part 2 when needed, do not recreate the code from these functions. Example Ouput Here is an example output of the game link to video: The maximum you can grab is 4 - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 - How many will you grab? 3 You took 3, I took 2 The maximum you can grab is 4 - 1 2 3 4 5 6 7 8 9 10 11 12 - How many will you grab? 3 You took 3, I took 3 The maximum you can grab is 4 - 1 2 3 4 5 6 - How many will you grab? 2 You took 2, I took 1 The maximum you can grab is 4 - 1 2 3 - How many will you grab? 2 The player won Do you wany to play again (Yes/No)? n Final Record: You won 1 game. I won games. Thanks for playing! import random random.seed (1) # Name: # Date: 278/21 # Class: 3 # Project: Nimgrab Strategy Game # Part: 3 Functions def getPlayerChoice(): number = int(input("How many will your grab? ")) while (number 4) or (number > 17): print ("Invalid Value") number = int(input("How many will your grab? ")) return number def getCompChoice(): smart_choice = random.randint(1, maxCanGrab) return smart_choice def printBoard(number): print "-", for i in range (1, number+1): print i, print ("-") def printFinalRecord (number, number2): print ("Final Record: ") print ("You won " + str(number) + print ("I won " + str(number2) + games") games") # ======= Main Program maxCanGrab numbers Left 4 17 # The maximum number of values that can be grabbbe # The number of values left on the board print ("You took " + str(getPlayerChoice())) print ("I took + str(getCompchoice())) printBoard(numbersLeft) printFinalRecord(5,0) || Start Create List of Numbers (Initialize the variables: max number to grab, number of values on the board) True While there are grater than 0 numbers left? Play again? True Display the numbers on the board Display how many games the player and computer won Get the player's number to grab FINISH Subtract the player's choice from the board True Display the play won Are there are grater than 0 numbers left? False Get the computer's number to grab Subtract the computer's choice from the board True Display computer won Are there are grater than 0 numbers left False Display the choices

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

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

More Books

Students also viewed these Databases questions