caishugame.m

来自「Matlab基础程序联系: 猜数游戏」· M 代码 · 共 36 行

M
36
字号
function  canshugame()
clc;
disp('welcome to play guess number game!');
time = input('Input a number(You can setting the max time you want):');
if time > 10
    disp('very easy!');
elseif time > 7
    disp('it is normal!');
else
    disp('very hard!')
end 
b = fix(rand(1)*100);
while time > 0
     a = input('Please input a number between 0-100: ');
     if a > b
         disp('the number your input is bigger!');
     elseif a<b
         disp('the number your input is smaller!');
     elseif a==b
         disp('You win!');
         break;
     else
            disp('your input is not a number! Please input again!');
            time = time + 1;
     end
     time = time - 1;     
end
if time <= 0
   disp('Your loss!');
end
reply = input('Do you want to play again? Y/N [Y]: ','s');
if (reply == 'Y')|(reply == 'y')
    canshugame();
end
    
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?