1, the write function, passing the n parameter returns the maximum and minimum
Method one: Use the algorithm
def func(*args): m = args [0] # is assumed that the maximum value of the zeroth item mi = args [0] # is assumed that the minimum value of zero entries for el in args: if m < el: the m = if mi > el: mi = the return { 'maximum': m, 'minimum': mi} print(func(1,24,56,5,28,89))
Method two: Use max () and min () function
. 1 DEF FUNC (* args): 2 return { ' maximum ' : max (args), ' minimum ' : min (args)} . 3 Print (FUNC (1,24,56,5,28,89))
2, write function, passing a number n, returns the factorial of n
1 def func(arg): 2 i = 1 3 n = 1 4 for c in range(arg): 5 i = i * n 6 n = n + 1 7 return i 8 print(func(8))
3, write function that returns a deck of cards, a total of 52, each of which is a tuple
For example: [( 'Red', 'A'), ( 'plum', 'A'), .....]
result = [] def func(): Colors = [ ' plum ' , ' red ' , ' block ' , ' spade ' ] numbers = ['A',2,3,4,5,6,7,8,9,10,'J','Q','K'] for number in numbers: for color in colors: result.append((color,number)) return result print(func())
4、