各位同学,创作不易,能否在文末打赏一瓶饮料呢?(^ _ ^)(文章末尾右下角处)
西北工业大学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)
建议大概了解下述函数库的基本运用之后再完成题目会更顺利。
注意区分/和//的区别
reversed函数返回一个反转的迭代器。(注意返回的是迭代器而不是字符串)
语法:reversed(seq)
join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。
语法:s=''.join(list)
(''内部是间隔方式,join()内是列表或者字符串之类的)
round() 方法返回浮点数x的四舍五入值。(round函数并不总是四舍五入,会受计算机表示精度的影响,同时也受python版本影响)
语法:round( x [, n] )
import math
x1=int(input())
y1=int(input())
x2=int(input())
y2=int(input())
x3=int(input())
y3=int(input())
a=(x1-x2)*2
b=(y1-y2)*2
c=(x1-x3)*2
d=(y1-y3)*2
e=((x1*x1-x2*x2)-(y2*y2-y1*y1))
f=((x1*x1-x3*x3)-(y3*y3-y1*y1))
x0=-(d*e-b*f)/(b*c-a*d)
y0=-(a*f-c*e)/(b*c-a*d)
r=math.sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))
print("%.3f"%r,"%.3f"%x0,"%.3f"%y0,sep=',')
# Code By Phoenix_ZH
n=int(input())
p=n
m=int(input())
ans=0
for i in range(0,m):
ans=ans+n
n=n*10+p
print(ans)
# Code By Phoenix_ZH
def isD(a, b):
if (a=='9'and b=='6') or (a=='6'and b=='9') or a == b:
return True
else:
return False
n = int(input())
flag = True
for i in range(len(str(n))>>1):
if isD(str(n)[i], str(n)[len(str(n))-i-1])==False:
flag = False
if flag:
print("Yes")
else:
print("No")
# Code By Phoenix_ZH
n=int(input())
n=str(n)
# m=''.join(reversed(n))#翻转
m=n[::-1]#翻转
if(n==m):
print("Yes")
else:
print("Not")
# Code By Phoenix_ZH
n=int(input())
a,b,c,t=1,1,1,n-2
while t:
c=a+b
a=b
b=c
t-=1
print(c)
# Code By Phoenix_ZH
def count(x):
sum=0
while x:
sum+=x%10
x//=10
return sum
n=int(input())
ans=0
while n:
ans+=1
n-=count(n)
print(ans)
# Code By Phoenix_ZH
n=int(input())
ans=0
for a in range(0,9+1):
for b in range(0,9+1):
for c in range(0,9+1):
for d in range(0,9+1):
if(a+b+c+d==n):
ans+=1
print(ans)
# Code By Phoenix_ZH
a=float(input())
b=float(input())
c=float(input())
d=float(input())
e=float(input())
f=float(input())
if a/d == b/e and a/d != c/f:
print("error")
else:
x=(c*e-f*b)/(a*e-d*b)
y=(c*d-a*f)/(b*d-e*a)
print("%.3f"%x,"%.3f"%y)
# Code By Phoenix_ZH
n=int(input())
ans=1
for i in range(1,n+1):
ans=ans*i
num=0
while(ans%10==0):
num+=1
ans=ans//10
print(num)
# Code By Phoenix_ZH
x1=int(input())
y1=int(input())
x2=int(input())
y2=int(input())
x3=int(input())
y3=int(input())
x4=int(input())
y4=int(input())
if(abs((y2-y1)/(x2-x1))==abs((y4-y3)/(x4-x3))):
print("Yes")
else:
print("No")
# Code By Phoenix_ZH