EducoderEducoderEducoder作业】绘制炸弹轨迹 II——绘制 n 个坐标点

T1T1T1 解决问题1的准备工作:分支

判断就行,需要注意的是m==1or m==3m == 1or\ m==3m==1or m==3m==1or3m == 1 or 3m==1or3是不一样的。牵着表示的是判断mmm111还是333,后者必定返回TrueTrueTrue

m = eval(input())
########## Begin ##########
if m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12 :
    print('yes')
else :
    print('no')
########## End ##########

T2T2T2 在合理范围绘制一个坐标点

其本质还是一个特判。

import math
########## Begin ##########
import matplotlib.pyplot as plt #导入库
h, v0, g = 3000, 200, 9.8       #设置参数值
t = eval(input())               #读取时刻t
tmax = math.sqrt(2 * h / g)
if t < 0 or t > tmax :
    print('输入错误')
else :
    print('绘制坐标')
    xt = v0*t                       #计算横坐标
    yt = h-1/2*g*t**2               #计算纵坐标
    plt.plot(xt,yt,'ro')            #绘制点(xt,yt)
    plt.grid('on')                  #显示网格线
    plt.axis([0,5000,0,h])          #设置坐标轴范围
    plt.show()                      #显示图形
########## End ##########

T3T3T3 解决问题2的准备工作:while循环

这个题目是容易的,关键是明白他和C++C++C++中的whilewhilewhile循环没有任何区别。都是先判断,再进循环,每次结束之后都判断。特别注意,别忘了每次更改循环变量。

########## Begin ##########
i = 1
ans = 0;
while i < 1000 :
    ans += i
    i += 2
print(ans)
########## End ##########

T4T4T4 绘制n个坐标点

我们跟炸弹过不去了…就是各种绘制炸弹,这个题就是绘制nnn个坐标,用whilewhilewhile循环实现即可。

import math
########## Begin ##########
import matplotlib.pyplot as plt #导入库
h, v0, g = 3000, 200, 9.8       #设置参数值
t = 0
n = 30

tmax = (2 * h / g) ** 0.5

dlt = tmax / (n - 1)
while t <= tmax : 
    xt = v0*t                       #计算横坐标
    yt = h-1/2*g*t**2               #计算纵坐标
    plt.plot(xt,yt,'ro')            #绘制点(xt,yt)
    t += dlt
plt.grid('on')                  #显示网格线
plt.axis([0,5000,0,h])          #设置坐标轴范围
plt.show()                      #显示图形
########## End ##########

plt.savefig( 'src/step4/student/pic.png' )
plt.close()

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐