作业帮 > 英语 > 作业

有2道PYTHON题求解答

来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/18 01:24:43
有2道PYTHON题求解答
Exercise 3.9
Test if the t value read in the program from Exercise 3.7 lies between 0 and 2*v0/g.if not,print a massage and abort execution.Name of program file:ball_cml_errorcheck.py
3.7的题目如下
Modify the program listed in exercise such that v0 and t are read from the command line.(v0=3,t=0.6)
然后3.
import sys
v0=float(sys.argv[1])
t=float(sys.argv[2])
g=9.81
y=v0*t-0.5*g*t**2
print y
= =想问下3.9这道题怎么做……咱还是新手刚学~
知道开头是这样
import sys
try:什么什么什么
except:什么什么什么
还有一道额……
Exercise 3.10
Instead of printing an error message and aborting the program explicitly,raise a valueerror exception in the if test on legal t values in the program from Exercise 3.9.The exception message should contain the legal interval for t.
import sys
try:
v0=float(sys.argv[1])
t=float(sys.argv[2])
g=9.81
if t2*v0/g:
raise
y=v0*t-0.5*g*t**2
print y
except:
print "t invalid"
import sys
try:
v0=float(sys.argv[1])
t=float(sys.argv[2])
g=9.81
s=2*v0/g
if ts:
raise
y=v0*t-0.5*g*t**2
print y
except:
raise ValueError,"t shold be in%s"%repr([0,s])