1、验证哥德巴赫猜想:一个不小于7的偶数可以表示为两个素数之和
def Sub(n):
fg=True
for i in range(2,n-1):
if n%i==0:
fg=False
break
if fg==True:
return True
n=input("请输入一个不小于7的偶数:")
for i in range(2,n):
for j in range(2,i):
if i+j==n and Sub(i) and Sub(j):
print n,"=",i,"+",j
def Max(a,b):
if a>b:
return a
else:
return b
m=input("请输入一个数:")
n=input("请再输入一个数:")
print "最大的数是:",Max(m,n)
def Sum(n):
sum=0
for i in range(1,n+1):
temp=2*i-1
sum+=temp
return sum
k=input("请输入n值:")
print "函数值为:",Sum(k)
def S(list):
for i in range(0,n):
for j in range(0,n-1):
if l1[j]>l1[j+1]:
temp=l1[j]
l1[j]=l1[j+1]
l1[j+1]=temp
return list
l1=[1,2,3,-5,-4,5,9,-8,-1]
n=len(l1)
print S(l1)