web123456

"Basic Tutorial on Python Programming and Algorithm (Second Edition)" Jiang Hong Yu Qingsong After-class Multiple Choice Questions Answers for Fill in the Blanks after-class Questions after-class Fill in the Blanks answers

  • The number of executions of the following Pyrhon loop body is different from the others A
    A. i=0
         ~~~~     while(i <= 10):
               ~~~~~~~~~~           print(i)
               ~~~~~~~~~~           i = i + 1
    = 10
         ~~~~     while(i>0):
               ~~~~~~~~~~           print(i)
               ~~~~~~~~~~           i=i-1
    C. for i in range(10):
               ~~~~~~~~~~           print(i)
    D. for i in rarge(10, 0, -1):
               ~~~~~~~~~~           print(i)
    A 11 times B 10 times C 10 times D10 times

  • The result of executing the following Python statement is A
    x=2;y=2.0
    if(x==y): print(“Equal”)
    else: print(“Not Equal”)
    A. Equal
    B. Not Equal
    C. Compilation error
    D. Runtime error

  • The result of executing the following Python statement is B
    i = 1
    if (i): print(True)
    else: print(False)
    A. Output 1
    B. Output True
    C. Output False
    D. Compilation error

  • Use the if statement to represent the following segment function f(x), the following program is incorrect A
    f(x) = (2x+ 1) x≥1
           ~~~~~~       = 3x/(x-1) x< 1
    A. if(x>=1):f=2 * x+1
    f=3 * x/(x- 1)
    B. if (x>=1): f=2 * x+1
    if (x<1): f=3 * x/(x-1)
    C. f = 2 * x+ 1
    if (x<1): f=3 * x/(x-1)
    D. if (x<1): f=3 * x/(x-1)
    else: f= 2 * x+1
    Just find a number to substitute

  • The following if statement counts the number of people who meet the conditions of "gender is male, rank is professor, age (age) is less than 40 years old". The correct statement is B
    A. if (gender == “Male” orage<40 and rank == “Professor”): n+=1
    B. if (gender == “male” and age<40 and rank == “professor”): n+=1
    C. if (gender == “male” and age<40 or rank == “professor”); n+=1
    D. if (gender == “male” or age<40 or rank == “professor”): n+=1

  • The following program segment finds the large number among the two numbers x and y. DIt's incorrect
    A. maxMum= x if x > y else y
    = (x,y)
    (x>y): maxNum = x
    else: maxNum = y
    (y>=x): maxNum=y
    maxNum=x

  • The following if statement counts the number of boys with excellent scores and boys who fail the score. The correct statement is C
    A. (gender= = "male" and score<60 or score>=90): n+=1
    B. if(gender == “male” and score<60 and score>=90): n+=1
    C. if (gender =="male" and (score<60 or score>=90)): n+=1
    D. if (gender = = "male" or score<60 or score>=90): n+=1

  • Use the if statement to represent the following segmented function:
    y = x^2-2x+3 x<1
    = sqrt(x-1) x≥1
    The following program segment is incorrect B
    A. if(x<1):y=x * x- 2 * x + 3
    else:y=(x-1)
    B. if(x≤1):y = x * x- 2 * x + 3
    y = math. sqrt(x-1)
    C. y = x * x - 2 * x + 3
    if(x>= 1):y= (x-1)
    D. if(x<1): y = x * x - 2 * x + 3
    if(x>=1):y = math. sqrt(x-1)

  • In the following statement structure, A cannot complete the accumulation function of 1 to 10 A
    A. for i in range(10,0): total += i
    B. for i in range(1,11): total += i
    C. for i in range(10,0,-1): total += i
    D. for i in (10,9,8,7,6,5,4,3,2,1): total+=i