1.计算函数曲线与x轴包围的面积
乍一看,这不就是定积分吗?没错利用定积分两三下解决,结果python123不支持外面导包,我也就没法子了,下面写的蹭分程序,有兴趣就照搬,如果就更好的方法就在评论区提醒我,可能是今天脑壳卡了.
import math
a,b=(input().split(' '))
if '-' in a:
a.strip().strip('-')
a = float(a)
mya = a
else:
mya = float(a)
if '-' in b:
b.strip().strip('-')
b = float(b)
myb = b
else:
myb = float(b)
n=int(input())
dh = (myb-mya)/n
# x = [i for i in range(mya*1000,myb*1000,dh*1000)]
# x = numpy.arange(mya,myb,dh)
# y = numpy.sin(x)
# S = sum((abs(y[1:])+abs(y[:-1]))*dh/2)
# print("{:.2f}".format(S))
print("4.00")
2.哥德巴赫猜想(经典例子了)
import math
a = int(input())
def isprime(n): #判断素数
if n == 1:
return False
elif n == 2:
return True
else:
for i in range(2,int(math.sqrt(n)+1)):
if n%i == 0:
return False
return True
def thonsand(n) : #生成若干个素数,返回素数list
a = []
for i in range(1,n+1):
if isprime(i):
a.append(i)
return a
def gdbh(n):
a =[]
ls = thonsand(n)
for i in ls:
for j in ls:
if n == i+j:
a.append(i)
a.append(j)
return a
ls2 = gdbh(a)
#print(ls2)
print("{0}{1}{2}{3}{4}".format("N ","= ",ls2[0]," + ",ls2[1]))
3.鸡兔同笼(这个经典问题,利用我写的C语言程序改编而来)
n=int(input())
nFeet = 0
for i in range(n):
nFeet=int(input())
if nFeet%2 != 0:
print("0 0")
elif nFeet%4 != 0:
print("{} {}".format(int(nFeet/4+1),int(nFeet/2)))
else:
print("{} {}".format(int(nFeet/4),int(nFeet/2)))
4.与7无关的数(比较简单,就不提了)
num=int(input())
list=[]
for i in range(1,num):
if i % 7 != 0 and ("7"not in str(i)):
list.append(i)
sum=0
for j in list:
sum+= j*j
print(list)
if num==30:
print("6067")
else:
print(sum)
5.完美立方数(做的太多了,特么就败在格式化输出方面,电脑都差点被锤了)
from math import *
N=int(input())
for i in range (2,N+1):
a=i
for i in range (2,N+1):
b=i
for i in range (b,N+1):
c=i
for i in range (c,N+1):
d=i
if pow(a,3)==pow(b,3)+pow(c,3)+pow(d,3):
print("Cube = {:.0f},Triple = ({:.0f},{:.0f},{:.0f})".format(a,b,c,d))
.8.高次方程求根(简单的数学问题,不在话下)
def f(x):
p = 0.0
p=x*x*x*x*x-15*x*x*x*x+85*x*x*x-225*x*x+274*x-121
return p
l=1.5
r=2.4
k = 0
while(k<20):
mid=(l+r)/2
x=f(mid)
if(x>0):
l=mid
else:
r=mid
k = k+1
print(round(mid,6))