python Lesson (function)

1, the definition of the function

Can be used in Python defkeyword to define functions and variables as each function also has a famous name, but naming naming rules are rules and variables are the same. Can be passed in parentheses after the function name placed to function parameters, function and math on this is very similar in function parameters of the program is equivalent to saying the mathematical argument of a function, and the function execution is complete we can by returnto return a key value, which is equivalent to saying that the dependent variable mathematical functions.

2, exercises

Exercises:

def getNumber(n):
    for i in range(1,n):
        count = i * (3*i-1) / 2
        print('%d'%count,end = " ")
        if i % 10 == 0:
            print()
getNumber(100)

Exercise 2:

DEF numOfDay ():
     for I in Range (2010,2021 ):
         IF (I%. 4 == 0 and I = 0% 100! or I 400% == 0):
             Print ( " % D there were 366 days ' % I)
         the else :
             Print ( ' % D there were 365 days ' % I) 
numOfDay ()    

Exercise 3:

def sushu():
    for i in range(2,32):
        for j in range(2,i):
            if  i % j == 0:
                break
        else:
            for n in range(i+1):
                if (2**n) - 1 == i:
                     print('%d      %d'%(n,i))           
sushu()               

Guess you like

Origin www.cnblogs.com/hmm01031007/p/11298701.html