python第四周程序控制练习题
#奇数为正,偶数为负,从一开始递加 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
相关推荐
LczPtr 2020-07-17
lqxqust 2020-06-01
清溪算法 2020-05-25
Lius 2020-05-11
流云追风 2020-04-22
xiaoyutongxue 2020-04-19
huavhuahua 2020-04-15
ITxiaobaibai 2020-03-07
陈云佳 2020-03-05
linmufeng 2020-02-21
waitwolf 2020-02-21
范范 2020-02-14
贤冰 2020-02-02
GoatSucker 2020-01-24
老和山下的小学童 2020-01-13
zhangchaoming 2020-01-04
xiefei0 2013-07-26
wannagonna 2013-07-21