Write a script that generates a random integer number between 1 and 10 (you will need to use rand and round(…)functions. Prompt player to guess number. Using a while loop, continue prompting the user until the correct number is guessed. Output both the correct number and the number of guesses.
ask=input('Enter a number between 1 and 10:');
number=1+round(rand*(9));
total=0;
while ask~=number
if(number<1 || number>10); disp('Invalid') total=guess+1; ask=input('Enter a number between 1 and 10:'); else if(ask==number) fprintf('% is correct',ask); else fprintf('%is incorrect',ask); guess=input('Enter a number between 1 and 10:'); end total=total+1; endendfprintf('Your answer is correct %g',ask==number);
Best Answer