Question: Declare a function in python named input _ guess. The function will prompt for and eventually return the user's row or column guess. More specifically,
Declare a function in python named inputguess. The function will prompt for and eventually return the user's row or column guess. More specifically, the function takes in an int parameter representing the size of the grid, a str parameter representing a specification of row or column, and an int return type. Since the caller of this function can be expected to provide a correct argument for the str parameter, specifically one that is "row" or "column, we will "assert" this assumption in our code such that an error is raised if it is not found to be true. As the first line of code in your function's body, add the following assert statement and fill in the blank I with your second parameter's name:
assert "row" or "column"
Declare a function named printgrid. Given the size of the grid, the user's row and column guesses, and whether the guesses were correct the function will print a grid of boxes to represent the game board. The function has:
An int parameter representing the size of the grid.
An int parameter representing the row guess.
An int parameter representing the column guess.
A bool parameter representing if the user's guess was correct.
A None return type.
Declare a function named correctguess. Given the secret boat locatior and the user's guess, the function will return if the user was correct or not. The function should take in four int parameters representing the secret row, the secret column, the row guess, and the column guess, and it will return a bool.
Now, it's finally time to implement the main function that will pull together each of the smaller pieces that you created in your program. Similar to your other functions, the main functions has certain specifications including:
An int parameter for grid size.
An int parameter for secret row.
An int parameter for secret column.
A return type of None.
The "state" of a game refers to the variables you need to keep track of in memory in order to run the game. What variables do you need to keep track of Define those inside of main's body first.
Then, begin the game loop while the user still has turns left to play and the user hasn't won yet, you will want to do the following:
Print the current turn number in a format such as Turn Prompt the user for a row and column guess, relying on your function inputguess to obtain a guess within the proper bounds.
Verify the user's guess using correctguess.
Codify the emoji results of the user's guess by making use of your printgrid function.
If the user's guess is correct, the user has won! Print Hit! and You won in turns! where is replaced with the number of guesses it took. End the loop by updating the appropriate variables.
Otherwise, print Miss! and move on to the next turn.
If the user has exhausted all turns, print X Better luck next Time! Where X is literally the character X and end the game.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
