python第四周程序控制练习题

typhoonpython 2020-01-10

#奇数为正,偶数为负,从一开始递加
sum =0
for i in range(1,966):
    if i%2 == 0:
        i = -i
    sum += i
print(sum)
#一百以内素数之和
sum =0
for i in range(2,101):
    flg = 1 
    for j in range(2,i):
        if i % j == 0:
            flg = 0
    if flg == 1:
        sum +=i
        
print(sum)
#合格率计算方法一
n=eval(input())
List=[]
i=input()
while i !=‘‘:
    List.append(eval(i))
    i=i nput()
sum_up=0
for i in List:
    if i>=n:
        sum_up+=1
if len(List)==0:
    print("合格率为100.00%")
else:
    x=100*(sum_up/len(List))
    print("合格率为:{:.2f}".format(x))
#合格率计算方法二
n = eval(input())
a = []
count =0
for i in range(100):
    c=input()
    if c == ‘‘:
        break
    else:
        a.append(eval(c))
        if a[i] >= n:
            count += 1

if len(a) == 0:
    print("合格率为100.00%")
else:
    m = count/i
    print("合格率为{:.2f}%".format(m*100))
#四叶玫瑰数
for i in range(1000,9999):
    i+=1
    a = i//1000 #千
    b = (i%1000)//100 #百
    c = (i%100)//10 #十
    d = i%10 #个
    if i == a**4 + b**4 + c**4 + d**4:
        print(i)
#用户登录(三次机会)不全对,找不出原因


count = 0
for i in range(10):
    k= input()
    u = input()
    if u == ‘666666‘and k==‘Kate‘:
        print("登录成功")
        break
    elif i == 2:
        print("3次用户名或者密码均有误!退出程序。")
        break

题目来源:python123.io

相关推荐