subject [1]： Run the following code .

subject [2]： Define function , Answer questions : have 5 personal , Among them 5 Personal ratio 4 Many individuals 20 element ; The first 4 individual
Human ratio 3 Many individuals 20 element ; The first 3 Personal ratio 2 Many individuals 20 element ; The first 2 Personal ratio 1 Many individuals 20 element ;
Known section 1 Personal 100 element . Excuse me, No 5 How much does an individual have ?（ Recursive call of function ）
Experimental code ：
def function(n): if n==1: return 100 return function(n-1)+20 print(function(5))
Running screenshot ：

subject [3]： Write two functions , A function finds the maximum of multiple numbers , A function averages multiple numbers
Experimental code ：
def seach_max(list): max=list[1] for x in list[1:]: if x>max: max=x return max
print('[11,56,33,5] Maximum ',seach_max([11,56,33,5])) def seach_ave(list): sum=0 for
xin list: sum+=x return sum / len(list) print('[11,56,33,5] Maximum ',seach_ave([11,56
,33,5])
Running screenshot ：

subject [4]： Write your own max function , Gets the maximum value of the element in the specified sequence . If the sequence is a dictionary , Take the maximum value of dictionary value

Experimental code ：
def max(list): if type(list) == dict: max_num = 0 for x in list: if max_num <
list[x]: max_num = list[x] else: max_num = list[0] for x in list: if max_num < x
: max_num = x return max_num param = {' Xiao Ming ':90, ' Zhang San ': 76, ' Monkey D Luffy ':30, ' floret ': 98}
print(max(param))
Running screenshot ：

subject [5]： Write your own rjust function , Create a string whose length is the specified length , The original string is right justified in the new string , The rest is filled with the specified characters

Experimental code ：
ef rjust(str1, width, fill_char): le = len(str1) # The processing specified width is smaller than the original string width if width < le
: width = le new_str = fill_char*(width-le) + str1 print(new_str) rjust('abc', 6
, '*')
Running screenshot ：

subject [6]： Write your own capitalize function , Can change the first letter of a specified string to uppercase

Experimental code ：
def capitalize(str): x = str[0] if 'a' <= x <= 'z': x = chr(int(ord(x)-32))
print(f'{x}{str[1:]}') else: print(str) capitalize('abc')
Running screenshot ：

subject [7]： Write your own isdigit function , Determines whether a string is a pure numeric string

Experimental code ：
def isdigit(str): for x in str: if not '0'<=x<='9': print(False) return print(
True) isdigit('1b345')
Running screenshot ：

subject [8]： Write your own upper function , Turns all lowercase letters in a string into uppercase letters

Experimental code ：
def upper(str): new_str = '' for i in str: if 'a' <= i <= 'z': new_str += chr(
ord(i) - 32) else: new_str += i return new_str print("aAbcD->",upper("aAbcD"))
Running screenshot ：

subject [9]： Write your own replace function , Converts the old string specified in the specified string to the new string specified

Experimental code ：
def replace(str,oldelem,newelem): str_list = str.split(oldelem) return newelem.
join(str_list) print('abclkj After replacement -》',replace("abclkj",'clk','opq'))
Running screenshot ：

Technology
Daily Recommendation
views 1