编程语言
首页 > 编程语言> > python课后实验(2)

python课后实验(2)

作者:互联网

1、
for i in range(100,1000):
    s = str(i)
    if int(s[0])**3+int(s[1])**3+int(s[2])**3==i:
        print(i,end=", ")

 

2、

a = eval(input("请输入年份:"))
b = a%400
c = a%4
d = a%100
if b == 0 or (c == 0 and d !=0):
    print(a, " 是闰年")
else:
    print(a, "不是闰年")

 

3、

n = 0
for i in range(1, 1001):
    s = 1
    for j in range(2, i):
        if i % j == 0:
            s = s + j
    if s == i:
        n = n + 1
print('1000以内共有{}个完数'.format(n))

 

 

4、

s1 = sorted(a)
s2 = sorted(b)
if s1 == s2:
    print("是换位字符串")
else:
    print("不是换位字符串")

 

5、

a,b,c=float(input("第一条边:")),float(input("第二条边")),float(input("第三条边"))
if a>b :
    a,b=b,a
if a>c :
    a,c=c,a
if b>c :
    b,c=c,b
if a+b<=c :
    print('不能构成',end='')
else:
    print('能构成',end='')
    if a==b and b==c:
        print('等边',end='')
    elif a==b or b==c:
        print('等腰',end='')
    if a**2+b**2==c**2:
        print('直角',end='')
    elif a!=b and b!=c:
        print('普通',end='')
print('三角形')

 

6、

n=int(input('请输入百分制学生成绩'))
if 90<=n<=100 :
    print('A')
elif 80<=n<=89:
    print('B')
elif 70<=n<=79:
    print('C')
elif 60<=n<=69:
    print('D')
elif 0<=n<=59:
    print('不及格')
else:
    print('非法百分制成绩')

 

7、

n=input("请输入以;间隔的数字串:")
c = n.split(";")
m=0
for i in c:
    m+=eval(i)
print(m)

 

标签:a%,python,float,int,range,实验,课后,print,input
来源: https://www.cnblogs.com/lxhlxwly/p/16269060.html