
上QQ阅读APP看书,第一时间看更新
3.5 实战训练

实战训练
实战1:定义变量,计算长方形的周长与面积。
编写程序,通过定义变量来计算长方形的周长与面积,程序运行效果如图3-18所示。

图3-18 实战1程序运行效果
实战2:根据输入的学生成绩,对成绩进行统计操作。
编写程序,输入学生的成绩,当输入负数时,程序结束。根据输入的数据计算全班的平均成绩,并统计90分以上的学生个数、80~90分的学生个数、70~80分的学生个数、60~70分的学生个数,以及不及格的学生个数。程序运行效果如图3-19所示。

图3-19 实战2程序运行效果
实战3:根据输入的数字,判断该数字的位数。
编写程序,根据用户输入的数字,判断该数字是几位数。程序运行效果如图3-20所示。

图3-20 实战3程序运行效果