1, to achieve 1 + 2! +3! +4! +5! + ... + n!
1 '' ' is calculated +3 2 + ... + 1 + n!!! ' '' 2 n = int (INPUT ( ' input values n: ' )) . 3 totalnum = 1 . 4 for I in Range (2, . 1 + n- ): . 5 NUM =. 1 . 6 for J in Range (. 1,. 1 + I ): . 7 NUM = NUM * J . 8 S = NUM . 9 totalnum + = S 10 Print (totalnum)
2, enter an integer, and determines whether the number daffodils
1 '' ' narcissistic number function definition ' '' 2 DEF Daffodil (NUM): . 3 numcopy = NUM . 4 A = [] . 5 the while NUM: . 6 X 10% = NUM . 7 a.append (X) . 8 NUM = NUM / / 10 . 9 L = len (A) 10 Summ = 0 . 11 for I in A: 12 is Summ Summ = I + ** L 13 is IF Summ == numcopy: 14 return True 15 the else : 16 return False . 17 '' ' function call ' '' 18 is LL = Daffodil (int (INPUT ( ' Enter an integer, the number is calculated whether daffodils: ' ))) . 19 Print (LL)
3, enter an integer (n> = 1000), lists all the number n of from 100 to daffodils
1 '' ' narcissistic number determination, and returns 100> daffodils all numbers n, and accept parameter n> = 1000 ' '' 2 DEF Daffodilnum (n): . 3 dafnumlist = [] . 4 for I in Range (100 , n-+. 1 ): . 5 m = Daffodil (I) . 6 IF m iS True: . 7 dafnumlist.append (I) . 8 Print (dafnumlist) . 9 10 Daffodilnum (int (iNPUT ( ' input n> = an integer of 1000: ' ) ))
4, the range of i, j, k are both [1, 1000], find i ^ 2 + j ^ 2 = k ^ 2 values of all
1 def get(): 2 u = 0 3 m=[] 4 n=[] 5 h=[] 6 for i in range(1,1001): 7 for j in range(1,1001): 8 k = 1000-i-j 9 if i**2 + j**2 == k**2: 10 '''列表添加用append()''' 11 m.append(i) 12 n.append(j) 13 h.append(k) 14 u=u+1 15 return m,n,h,u 16 17 [f,d,s,u] = get() 18 print(f,d,s,u)