Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Guessing game 2 In a computer generated guessing game, the player should guess a number between 1 and 20 . The player has 5 guesses.

image text in transcribed
image text in transcribed
image text in transcribed
Guessing game 2 In a computer generated guessing game, the player should guess a number between 1 and 20 . The player has 5 guesses. The player wins if the difference between fwo or more guesses with the actual number is smaller than or equal to 3. Ex: The number to be guessed is 9 . The player's guesses are [2,14,10,7,3]. Since 10 is larger than 9 by 1 , and 7 is smaller than 9 by 2 , the player has won this set of the game. Write a function called NumberGuess() that takes the number to be guessed and a player's guess anray, caiculates if the wincing criteria is met, and returns logical 1 for if the player wins and logical 0 if the player did not. Ex: Given: gameNum = 13; and userGuess =[2,5,12,17,19]; Output: win = logica 1 1 function win = NumberGuess (gamellum , userGuess) x write a function that takes the elesents of the row array of user's guesses: z and calculates if the difference of 2 or more of the guesses is less, than 3 . win = end Code to call your function ? 1 gameNum = randi ([1,20],1) 2 userGuess = randi ([1,2],[1,5]) 1 win = NumberGuess (gameNum , usenGuess) Check if gameNum =11, userGuess =[10,2,13,14,20] returns logical 1 Check that given a random gameNum and userGuess, win is calculated correctly

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

Beyond Greed And Fear Understanding Behavioral Finance And The Psychology Of Investing

Authors: Hersh Shefrin

1st Edition

0195161211, 978-0195161212

Students also viewed these Databases questions

Question

Write code that outputs the following. End with a newline. egg mud

Answered: 1 week ago

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago