第一题
height=input()
160
weight=input()
50
bmi=weight/((height/100.0)*(height/100.0))
bmi=round(bmi,2)
if bmi<18.5:
... print("体重过轻")
... elif (bmi>=18.5 and bmi<24):
... print("正常范围")
... elif (bmi>=24 and bmi<27):
... print("稍重")
... elif (bmi>=27 and bmi<30):
... print("轻度肥胖")
... elif (bmi>=30 and bmi<35):
... print("中度肥胖")
... elif (bmi>=35):
... print("重度肥胖")
...
正常范围
第二题
def is_leap_year(year):
if year % 100 ==0:
if year %400 ==0:
print ("%i是闰年"%year)
else:
print ("%i是平年" %year)
else:
if year %4==0:
print ("%i是闰年"%year)
else:
print ("%i是平年" %year)
year = input()
is_leap_year(year)
第三题
num=input()
10
score=1
if num <= 8 :
... score = 8num
... else num>8 && num <= 14:
... score = 88 + (num -8)*6
... else :
print("最多只能输入14")
print(score)
第四题
def judge(a,b,c):
for line in a,b,c:
if line <= 0:
print("False")
if ((a+b>c) and (a+c>b) and (b+c>a)):
print("True")
m = max(a,b,c)
if ((aa+bb==cc) or (aa+cc==bb) or (bb+cc==a*a)):
print("Rgith Triangle")
else:
print("Non-Right Triangles")
else:
print("False")
str_in = input()
num = [int(n) for n in str_in.split()]
print(num)
a=num[0]
b=num[1]
c=num[2]
print(a)
judge(a,b,c)
第五题
import math
def getSqrtNum(a,b,c):
for line in a,b,c:
if line <= 0:
print("False")
if (bb -4a*c)>=0:
x1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2
a
x2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2
a
if x1 != x2:
print("有两个异根:x1=%f,x2=%f", x1, x2)
else:
print("有两个同根:x=%f", x1)
else:
print("没有根")
str_in = input()
num = [int(n) for n in str_in.split()]
print(num)
a=num[0]
b=num[1]
c=num[2]
print(a)
getSqrtNum(a,b,c)
第六题
def pyramid(n):
for i in range(1,n):
print(' '(n-(i-1))+' '*(i))
pyramid(4)
第七题
def getMaxG(x,y):
if x > y :
smaller = y
else:
smaller = x
for i in range(1,smaller+1):
if ((x%i == 0) and (y%i == 0)):
hcf = i
print(hcf)
str_in = input()
num = [int(n) for n in str_in.split()]
print(num)
a=num[0]
b=num[1]
getMaxG(a,b)
第八题
import math
def getCount(n):
num=0
if n < 0:
print("负数没有阶乘,请输入正整数")
elif n == 0:
print("0的阶乘是1")
else:
for i in range(1,n+1):
num = num + math.factorial(i)
print(num)
a=input()
getCount(a)
第九题
def perfectNum(n):
total = 0;
for i in range(1,n):
if n%i == 0:
total +=i;
if n == total:
print(n)
for i in range(1,501):
perfectNum(i)
第十题
def fibo(n):
stack=[]
if n == 0 or n == 1 :
reduce(1)
else:
stack.append(1)
stack.append(1)
for i in range(2,n):
stack.append(stack[i-1] + stack[i-2])
stack.insert(0,0)
return stack
n = input()
fibo(n)
print(fibo(n))
第十一题
def judgeNum(n):
ansewer=[1,2,3,4]
num=[]
right=0
right2=0
for i in n:
num.append(int(i))
for i in range(len(ansewer)):
if num[i]==ansewer[i]:
right +=1
for i in range(len(ansewer)):
for j in range(len(num)):
if num[j] == ansewer[i]:
right2 +=1
print ("%dA%dB"%(right,right2))
x = raw_input("guess number :")
judgeNum(x)
十二题
def getSqrt(x):
if x < 0:
return -1
low = 0
high =x
ans = (low + high)/2.0
while ans2 != x :
if ans2 > x:
high = ans
else:
low = ans
ans = (low + high)/2.0
return ans
x = int(raw_input("please input a int :"))
print(getSqrt(x))
十三题
def getList(array):
for i in range(len(array)-1):
for j in range(len(array)-i-1):
if array[j] > array[j+1]:
array[j],array[j+1] = array[j+1],array[j]
array=[9,8,7,6,5,4,3,2,1,0]
getList(array)
print (array)
第十四题
def getList(n):
array=[]
for i in n:
array.append(int(i))
for i in range(len(array)-1):
for j in range(len(array)-i-1):
if array[j] < array[j+1]:
array[j],array[j+1] = array[j+1],array[j]
return array
line = raw_input("please input number:")
array= getList(line)
print (array)