如何用Python初步实现判断汽车是否超速呢?小编用最基本的方法,使用红绿灯之间的距离和汽车通过时间,判断汽车是否超速,与大家分享判断原理。

程序输入的数据为红绿灯之间的距离,以及汽车通过的时间。

首先,读入红绿灯之间的距离,类型为浮点型数据。

接着,读入汽车通过红绿灯的时间。

计算汽车通过红绿灯时的速度,保存在变量v中。

输出汽车的行驶速度,如下图所示。

最后,用if-elif语句实现汽车是否超速的判断。

运行程序,输入红绿灯之间的距离和汽车行驶的时间后,电脑就会计算出车速并判断是否超速。

如何用Python初步实现判断汽车是否超速呢?小编用最基本的方法,使用红绿灯之间的距离和汽车通过时间,判断汽车是否超速,与大家分享判断原理。
程序输入的数据为红绿灯之间的距离,以及汽车通过的时间。
首先,读入红绿灯之间的距离,类型为浮点型数据。
接着,读入汽车通过红绿灯的时间。
计算汽车通过红绿灯时的速度,保存在变量v中。
输出汽车的行驶速度,如下图所示。
最后,用if-elif语句实现汽车是否超速的判断。
运行程序,输入红绿灯之间的距离和汽车行驶的时间后,电脑就会计算出车速并判断是否超速。