有2道PYTHON题求解答Exercise 3.9Test 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.py3.7的题目如下Modify the program listed
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 07:35:07
有2道PYTHON题求解答Exercise 3.9Test 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.py3.7的题目如下Modify the program listed
有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.
有2道PYTHON题求解答Exercise 3.9Test 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.py3.7的题目如下Modify the program listed
import sys
try:
v0=float(sys.argv[1])
t=float(sys.argv[2])
g=9.81
if t<0 or t>2*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 t<0 or t>s:
raise
y=v0*t-0.5*g*t**2
print y
except:
raise ValueError,"t shold be in%s"%repr([0,s])