如何使用以前的用户输入并将其放入另一个用户输入语句中


a = input('What is the name of the exoplanet? ','s');
mass = input('What is the mass of %s (kg)? ', a)
radius = input('What is the estimated radius of %s (km)? ', a)
masssp = input('What is the mass of the specimen (kg) ')
newton = (mass * radius)/masssp
fprintf('On %s , it would weight approxomately %d Newtons ', s, newton)

您的文本需要sprintf

a = input('What is the name of the exoplanet? ','s');
mass   = str2num(input(sprintf('What is the mass of %s (kg)?', a),'s'));
radius = str2num(input(sprintf('What is the estimated radius of %s (km)?', a),'s')) ;

然后将字符串转换为数字,否则无法使用它进行计算…

相关内容

  • 没有找到相关文章

最新更新