print("2.计算1+2+3+。。。+100的和")
sum = 0
for i in range (1,101):
sum +=i
print(sum)
print("3.计算10+9+8+。。。+1之和")
sum = 0
for i in range (10,0,-1):
sum += i
print(sum)
print("6.使用不同方法输出实现2000~3000所有闰年")
for i in range (2000,3001):
if(i%100==0 and i%400==0):
print(i,end=" ")
elif (i %100!=0 and i %4 ==0):
print(i,end=" ")
else :
pass
print("7.Sn=1-3+5-7+9-11+.....")
x=int(input("输入值x"))
Sn=0
for i in range (1,x+1):
if (i%2==0):
Sn-=2*i-1
else :
Sn+=2*i-1
print(Sn)
print("8.计算Sn=1+1/2+1/3+...")
n=int (input("请输入计算项数:"))
Sn=1
for i in range (2,n+1):
Sn+=1/i
print(str.format("Sn=1+1/2...+1/{0:1}={1:1.2f}",n,Sn))
print("9.打印九九乘法表")
def print1():
for i in range (1,10):
s=""
for j in range (1,10):
s += str.format("{0:1}*{1:1}={2:<2}",i,j,i*j)
print(s)
def print2():
for i in range (1,10):
for j in range (1,i+1):
s = str.format("{0:1}*{1:1}={2:<2}",i,j,i*j)
print(s, end=" ")
print()
def print3():
for i in range (1,10):
print(" "*7*(i-1),end="")
for j in range (i,10):
s = str.format("{0:1}*{1:1}={2:<2}",i,j,i*j)
print(s, end=" ")
print()
print1()
print2()
print()
import math
print("10.输入三角形3条边,判断是否构成三角形,若可以求周长面积,否则报错")
a=float(input("请输入第一条边:"))
b=float(input("请输入第二条边:"))
c=float(input("请输入第三条边:"))
mianji=0
zhouchang=0
h=0
if(a+b>c and a+c>b and b+c>a):
zhouchang = a+b+c
h=zhouchang/2
mianji = math.sqrt(h*(h-a)*(h-b)*(h-c))
print(str.format("三角形三边分别为 a = {0:1}, b = {1:1}, c = {2:1}",a,b,c))
print(str.format("三角形周长为 {0:1} 面积为 {1:1}",zhouchang,mianji))
else:
print("无法构成三角形")
import math
a=float(input("请输入系数a:"))
b=float(input("请输入系数b:"))
c=float(input("请输入系数c:"))
x=0
x1=0
x2=0
if a!=0 or b!=0:
if a==0 and b!=0:
x=-(c/b)
print("有一个实数根为: ",x)
elif b*b-4*a*c == 0:
x1=x2=-(b/(2*a))
print("有两个相等实根: ",x1)
elif b*b-4*a*c>0:
x1=-b/(2*a)+math.sqrt(b*b-4*a*c)/(2*a)
x2=-b/(2*a)-math.sqrt(b*b-4*a*c)/(2*a)
print("有两个不相等的实根: ",x1,x2)
elif b*b-4*a*c<0:
x1=-b/(2*a)+math.sqrt(4*a*c-b*b)/(2*a)
x2=-b/(2*a)-math.sqrt(4*a*c-b*b)/(2*a)
print(str.format("有两个不等实根:{0}+{1}i 和 {0}-{1}i",-b/(2*a),math.sqrt(4*a*c-b*b)/(2*a)))
else:
print("无解")
好了。至此我自己的作业做完了,为什么跳过一些题呢,是因为真的没时间了,机房时间还要解答同学的问题。