赞
踩
各位同学,创作不易,能否在文末打赏一瓶饮料呢?(^ _ ^)(文章末尾右下角处)
西北工业大学NOJ-Python程序设计作业题解集合:
NOJ-Python程序设计:第1季:水题(Season 1-Easy) (1-10)
NOJ-Python程序设计:第2季:小段代码(Season 2-Snippet) (11-20)
NOJ-Python程序设计:第3季:循环(Season 3-Loop) (21-30)
NOJ-Python程序设计:第4季:枚举算法(Season 4-Enumeration algorithm) (31-40)
NOJ-Python程序设计:第5季:模块化(Season 5-Modularization) (41-50)
NOJ-Python程序设计:第6季:字符串(Season 6-String) (51-60)
NOJ-Python程序设计:第7季:列表与元组(Season 7-List and Tuple) (61-70)
NOJ-Python程序设计:第8季:集合与字典(Season 8-Sets and Dictionary) (71-80)
NOJ-Python程序设计:第9季:类(Season 9-Class) (81-90)
NOJ-Python程序设计:第10季:挑战算法(Season 10-Challenges) (91-100)
建议大概了解下述函数库的基本运用之后再完成题目会更顺利。
import math
math.atan()
的输入参数是弧度而不是度。math.sqrt()
math.pow(x,y)
相当于求
x
y
x^y
xymath.acos()
可以同时提供分子(numerator)和分母(denominator)给构造函数用于实例化Fraction类,但两者必须同时是int类型或者numbers.Rational类型,否则会抛出类型错误。当分母为0,初始化的时候会导致抛出异常ZeroDivisionError。(自带约分简化的功能)
import fractions
x=fractions.Fraction(2,3)
a,c=x.numerator,x.denominator
round() 方法返回浮点数x的四舍五入值。(round函数并不总是四舍五入,会受计算机表示精度的影响,同时也受python版本影响)
语法:round( x [, n] )
import math
def hav(theta):
return math.pow(math.sin(theta/2),2)
def Cal(w1,j1,w2,j2):
w1=math.radians(w1)
j1=math.radians(j1)
w2=math.radians(w2)
j2=math.radians(j2)
d1=abs(w2-w1)
d2=abs(j2-j1)
h=hav(d1)+math.cos(w1)*math.cos(w2)*hav(d2)
ans=math.asin(math.sqrt(h))*2*6371
return ans
pass
w1=float(input())
j1=float(input())
w2=float(input())
j2=float(input())
ans=Cal(w1,j1,w2,j2)
print("{:.4f}km".format(ans))
# Code By Phoenix_ZH
'''
34.260958
108.942369
55.755825
37.617298
'''
import fractions
n=float(input())
n=int(n*10000000)
a=10000000#用于保护准确度
print(fractions.Fraction(n,10000000))
# Code By Phoenix_ZH
R=float(input())/255
G=float(input())/255
B=float(input())/255
MAX,MIN=max(R,G,B),min(R,G,B)
V,S=MAX,(MAX-MIN)/MAX
if MAX==R:
H=60*((MAX==R)*(0+((G - B)/(MAX-MIN))))
if MAX==G:
H=60*(MAX==G)*(2+((B - R)/(MAX-MIN)))
if MAX==B:
H=60*(MAX==B)*(4+(R-G)/(MAX-MIN))
# H=60*((MAX==R)*(0+((G - B)/(MAX-MIN)))+(MAX==G)*(2+((B - R)/(MAX-MIN)))+(MAX==B)*(4+(R-G)/(MAX-MIN)))
if(H<0):
H+=360
print("%.4f"%H,"%.4f%%"%(S*100),"%.4f%%"%(V*100),sep=",")
# Code By Phoenix_ZH
f=float(input())
n=int(input())
print(round(f,n))
# Code By Phoenix_ZH
import math
x=int(input())
y=int(input())
p=math.sqrt(x*x+y*y)
t=math.atan(y/x)
print("%.4f"%p,"%.4f"%t,sep=',')
# Code By Phoenix_ZH
n=int(input())
ans=10.5*min(n,2)+4*max(n-2,0)
print(int(ans))
# Code By Phoenix_ZH
import math
h=float(input())
r=float(input())
PI=math.acos(-1.0)
V=PI*r*r*h
S=PI*r*r*2+2*PI*r*h
print("%.4f"%V)
print("%.4f"%S)
# Code By Phoenix_ZH
import math
v=float(input())
T=float(input())
ans=13.12+0.6215*T-math.pow(v,0.16)*11.37+0.3965*T*math.pow(v,0.16)
print(round(ans))
# Code By Phoenix_ZH
import fractions
#By using fractions
a=int(input())
b=int(input())
c=int(input())
d=int(input())
s1=fractions.Fraction(a,c)
s2=fractions.Fraction(b,d)
a,c=s1.numerator,s1.denominator
b,d=s2.numerator,s2.denominator
print("(",a,"/",c,")","+","(",b,"/",d,")","=",s1+s2,sep="")
print("(",a,"/",c,")","-","(",b,"/",d,")","=",s1-s2,sep="")
print("(",a,"/",c,")","*","(",b,"/",d,")","=",s1*s2,sep="")
print("(",a,"/",c,")","/","(",b,"/",d,")","=",s1/s2,sep="")
# Code By Phoenix_ZH
import math
def isTriangle(a,b,c):
if a+b > c and a+c > b and b+c > a and abs(a-b) < c and abs(a-c) < b and abs(c-b) < a:
return True
else:
return False
a=int(input())
b=int(input())
c=int(math.sqrt(a*a+b*b))
c2=int(math.sqrt(abs(a*a-b*b)))
if(isTriangle(a, b, c)and(a*a+b*b==c*c)):
print("c")
elif(isTriangle(a, b, c2)and((a*a+c2*c2==b*b)or(b*b+c2*c2==a*a))):
if(c2==min(a,b,c2)):
print('a')
else:
print('b')
else:
print("non")
# Code By Phoenix_ZH
各位同学,创作不易,打赏一瓶饮料吧!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。